In C++ should you copy static data members in a copy constructor or assignment operator? Why or why not?
Asked
Active
Viewed 235 times
1
-
5What do you think and why? – Mohit Jain May 18 '17 at 09:48
2 Answers
3
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

knst
- 523
- 2
- 16
3
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.

Quentin
- 62,093
- 7
- 131
- 191