N
Nindi
I have just been looking again at http://www.gotw.ca/gotw/059.htm
What is wrong with a solution like :
class MyClass {
public:
MyClass():theA(...),theB(...){...}
MyClass(const MyClass
&theOther):theA(theOther.theA),theB(theOther.theB){...}
MyClass& operator=(const MyClass &theOther)
{
MyClass temp(theOther);
swap( (void *)(&theA),(void *)(&temp.theA),sizeof(InnerObject));
swap( (void *)(&theB),(void *)(&temp.theB),sizeof(InnerObject));
return *this;
}
static void swap(void *b,void *a,int count)
{
char temp;
for(int i(0);i<count;++i){
temp=((char*)(a));
((char *)(a)) = ((char *)(b));
((char *)(b))=temp;
}
}
InnerObject theA;
InnerObject theB;
};
to part 3 ?
What is wrong with a solution like :
class MyClass {
public:
MyClass():theA(...),theB(...){...}
MyClass(const MyClass
&theOther):theA(theOther.theA),theB(theOther.theB){...}
MyClass& operator=(const MyClass &theOther)
{
MyClass temp(theOther);
swap( (void *)(&theA),(void *)(&temp.theA),sizeof(InnerObject));
swap( (void *)(&theB),(void *)(&temp.theB),sizeof(InnerObject));
return *this;
}
static void swap(void *b,void *a,int count)
{
char temp;
for(int i(0);i<count;++i){
temp=((char*)(a));
((char *)(a)) = ((char *)(b));
((char *)(b))=temp;
}
}
InnerObject theA;
InnerObject theB;
};
to part 3 ?