I try to write a copy constructor for my vector of pointers to object initialized and declared in class Shop. The vector in consideration is:
std::vector <gCustomer*> vCustomer;
It has been also declared in the constructor of gShop and deleted via loop in the destructor.
Now I want to have a deep copy of the vector of pointers in the copy constructor. But nothing gets actually copied, a check of its size remains zero or crashes the program if I manage to run the program and access vCustomer. (Note if I leave the copy constructor out so that the default copy constructor is used, the program runs fine)
gShop::gShop(const gShop & cShop)
{
for(int i = 0; i < (int)vCustomer.size(); ++i)
{
vCustomer[i] = cShop.vCustomer[i];
}
}
Thanks
Note I also have an assigned operator
gShop gShop::operator=(const gShop & rhs)
{
if (this == &rhs) return *this;
for(int i = 0; i < (int)vCustomer.size(); ++i)
{
delete vcustomer[i];
vCustomer[i] = new gCustomer;
vCustomer[i]= rhs.vCustomer[i];
}
}