I have a class called arr and it has a function named _union written like this:
template<class T>
arr<T> *arr<T>::_union(arr<T> B) {
arr<T> *C(this->length + B._length());
bool isPresent = false;
for (int i = 0; i < length; i++)
C->push_back(this->get(i));
for (int j = 0; j < B._length(); j++) {
for (int k = 0; k < C->_length(); k++) {
if (B.get(j) == C->get(k))
isPresent = true;
}
if (!isPresent)
C->push_back(B.get(j));
isPresent = false;
}
return C;
}
The function returns a pointer of an object that was newly created inside this function's scope.
In main function, I wrote code like this :
arr<int> *a3 = a1._union(a2);
a3->display();
When I run, this gives me an error:

What is the problem here? If I don't use any pointers and just return normal object then everything is fine.
Please help me. Also I don't have any copy constructers inside the class. I am just trying to create my own array class with data and functions.
lengthinCwill be wrong in those cases where the containers contain elements that compare equal (since you don'tpush_backduplicates).