Originally Posted by
whiteflags
OK, well there is no real difference between what I wrote and a.push_back( Dog(4,4) ); It is copied anyway according to the reference page. But the problem must be with your copy constructor if you are pushing invalid objects into a.
I would want to see Dog's members and the available copy constructor to fix it.
yeah that is the problem, i didn't even have a copy constructor.
Code:
class Dog
{
char *name ;
int a, b ;
Dog(int x, int y)
{
a = x;
b = y ;
name = new int[5] ;
name="Jack
}
~Dog()
{
delete []name ;
// i think when it goes out of scope the destructor the destroys the
//memory location of name, but the object copied to the list would point to
//that memory address, and when i accessed it later i got a seg fault.
//maybe this idea is wrong then.
}
}