K
Kjell Arne Johansen
Hi
How does it work?
//This works
//Constructor is run and memory allocated for m_AnObject
CSomeClass SomeClass1;
//copying data works fine
SomeClass1 = SomeClass2;
//Oooops, constructor is not run. (Should it be?) Memory is not
//allocated for m_AnObject. Only copy constructor and assignment
//operator is run. How do I check if memory is allocated for
//m_AnObject???
SomeClass SomeClass1 = SomeClass2;
//The code
//Standard constructor
CSomeClass::CSomeClass()
{
m_AnObject = new CAnObject();
}
//Copy constructor
CSomeClass::CSomeClass(const CSomeClass& orig)
{
*this = orig;
}
//Assignment operator overriding
CSomeClass& CSomeClass:perator=(const CSomeClass& rhs)
{
if(this != &rhs)
{ //Does m_AnObject point to legal memory??
*m_AnObject = *rhs.m_AnObject;
}
return *this;
}
How do I find out if memory is already allocated?
Regards
Kjell Arne Johansen
How does it work?
//This works
//Constructor is run and memory allocated for m_AnObject
CSomeClass SomeClass1;
//copying data works fine
SomeClass1 = SomeClass2;
//Oooops, constructor is not run. (Should it be?) Memory is not
//allocated for m_AnObject. Only copy constructor and assignment
//operator is run. How do I check if memory is allocated for
//m_AnObject???
SomeClass SomeClass1 = SomeClass2;
//The code
//Standard constructor
CSomeClass::CSomeClass()
{
m_AnObject = new CAnObject();
}
//Copy constructor
CSomeClass::CSomeClass(const CSomeClass& orig)
{
*this = orig;
}
//Assignment operator overriding
CSomeClass& CSomeClass:perator=(const CSomeClass& rhs)
{
if(this != &rhs)
{ //Does m_AnObject point to legal memory??
*m_AnObject = *rhs.m_AnObject;
}
return *this;
}
How do I find out if memory is already allocated?
Regards
Kjell Arne Johansen