Declared in arraystorage class, private: string *names;
ArrayStorage& ArrayStorage::operator=(const ArrayStorage& rhs)
{
// possible error
names = new string[numOfElements];
return *this;
}
// copy constructor
ArrayStorage::ArrayStorage(const ArrayStorage& rhs):
names(new string[numOfElements]),
numOfElements(rhs.numOfElements)
{
//names = new string[this->getNumOfElements()];
for (int i = 0; i < this->getNumOfElements(); i++)
names[i] = rhs.names[i];
}
ArrayStorage::~ArrayStorage(void)
{
delete [] names;
}
================================ ArrayStorage.cpp==============================
My first problem, if I declare names as private, the whole thing doesn't work. It works if I put it as public.
Secondly, can you please advise, how do I make it work, if I want to declare string *names as private?
ArrayStorage arrayStorage4 = arrayStorage3;should call the constructor, notoperator=.privatevspublicis a red herring, unrelated to the actual problem. Please reduce your program to the smallest complete compilable program that demonstrates the problem and post that here. See sscce.org.