Class basic operators
Posted
by swan
on Stack Overflow
See other posts from Stack Overflow
or by swan
Published on 2010-05-08T12:37:43Z
Indexed on
2010/05/08
12:48 UTC
Read the original article
Hit count: 165
c++
Hi,
Is it necessary to have a copy constructor, destructor and operator= in a class that have only static data member, no pointer
class myClass{
int dm;
public:
myClass(){
dm = 1;
}
~myClass(){ } // Is this line usefull ?
myClass(const myClass& myObj){ // and that operator?
this->dm = myObj.dm;
}
myClass& operator=(const myClass& myObj){ // and that one?
if(this != &myObj){
this->dm = myObj.dm;
}
return *this;
}
};
I read that the compiler build one for us, so it is better to not have one (when we add a data member we have to update the operators)
© Stack Overflow or respective owner