#include "Array.h" Array::Array(int n) { size = n; array = new int[n]; } Array::Array() { size = 0; array = 0; } void Array::input() { for (int i = 0; i < size; i++) cin >> array[i]; } void Array::show() { for (int i = 0; i < size; i++) cout << array[i] << " "; } Array Array::connect(Array array2) { bool label = false; int count = 0; for (int i = 0; i < size; i++) { label = false; for (int j = 0; j < array2.size; j++) { if (array[i] == array2.array[j]) { label = true; break; } } if (label == false) count++; } Array array3(size + count); count = size; for (int i = 0; i < size; i++) array3.array[i] = array[i]; for (int i = 0; i < array2.size; i++) { label = false; for (int j = 0; j < size; j++) { if (array2.array[i] == array3.array[j]) { label = true; break; } } if (label == false) { array3.array[count] = array2.array[i]; count++; } } return array3; } Array::~Array() { delete[] array; } #include "Array.h" int main() { int n; cout << "Input Array_1 size: "; cin >> n; Array array1(n); cout << "Input Array_1 data: "; array1.input(); cout << "Input Array_2 size: "; cin >> n; Array array2(n); cout << "Input Array_2 data: "; array2.input(); Array array3 = array1.connect(array2); cout << "Result: " << endl; array1.show(); cout << endl; array2.show(); cout << endl; array3.show(); cout << endl; array1.~Array(); array2.~Array(); array3.~Array(); return 0; } Why is the data in objects normal before the connect function and distorted after it? Is it a fun pointers game?
connect, which returns an object by value. - AnT September