简体   繁体   中英

Should you copy static data members in a copy constructor or assignment operator?

In C++ should you copy static data members in a copy constructor or assignment operator? Why or why not?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM