So I have the following class:
class smartA
{
public:
int *p;
int size;
smartA(){size=10; p = new int [size];}
smartA (int x){size=x; p = new int [x];}
smartA(int y[], int x ){size=x; p = new int [x]; for (int i=0 ; i<x ; i++) p[i]=y[i];}
smartA(const smartA &a) {*this=a;}
~smartA(){delete [] p;}
void displayA()
{
for (int i=0; i<size; i++)
{ cout<<setw(4)<<p[i];
if (((i+1)%5)==0 && i!=0)
cout<<endl;}
cout<<endl<<endl;
}
void setsmartA(const int a[], int sizea)
{size=sizea; p = new int[size]; for (int i=0 ; i<size ; i++) p[i]=a[i];}
};
How can I write a function that merges two smart array objects into a third smart array objects. I am having trouble accessing the elements of each smart array since it has to be a dynamic array.
for example the adding following member function gives me an error:
smartA add(smartA a)
{
smartA c(a.size+size);
int i=0;
for ( ; i<a.size ;i++)
c.p[i]=a.p[i];
for (int j=0; j<a.size+size; j++, i++)
c.p[i]=p[j];
return c;}
std::vector? And what does "merge" mean in this context?{*this=a;}memory leak !!addis not a method ofsmartAso it does not have access to member variables likesizeandp, if you add it the class it does compile