J
John Fullman
I do this in several large classes to avoid rewriting copy ctr code. It
seems to work okay, but I was wondering if I might be shooting myself
in the foot later... I can't think of anything wrong with it, but it
looks like bad programming.
class MyClass
{
public:
//...
//Assignment operator defined
MyClass& operator=(const MyClass& copy)
{
if(this != ©)
{
//... do the copy...
}
}
//Copy constructor
MyClass(const MyClass& copy)
{
*(const_cast<MyClass*>(this)) = copy;
}
//...
};
seems to work okay, but I was wondering if I might be shooting myself
in the foot later... I can't think of anything wrong with it, but it
looks like bad programming.
class MyClass
{
public:
//...
//Assignment operator defined
MyClass& operator=(const MyClass& copy)
{
if(this != ©)
{
//... do the copy...
}
}
//Copy constructor
MyClass(const MyClass& copy)
{
*(const_cast<MyClass*>(this)) = copy;
}
//...
};