Reputation: 135
In C++ should you copy static data members in a copy constructor or assignment operator? Why or why not?
Upvotes: 1
Views: 261
Reputation: 63154
Static data members are nothing more than global variables, but whose name is scoped inside a class. Their static storage duration means that only a single instance of them exists for the whole program, and thus is "shared" by all of the instances.
"Copying static data members" would only mean copying these objects over themselves. It is, at best, useless.
Upvotes: 3
Reputation: 533
Static data member is static data of class and it means that owner of this data not a object, but the class.
Don't copy static data member, it is not needed
Upvotes: 3