简体   繁体   中英

C++: How is static class member implemented?

Where are static data members stored? Is there some kind of static members table (as in "virtual methods table")? I've performed an experiment - seems like static members don't affect sizeof() at all. Does it mean all references to static members are converted to a fixed address?

The C++ standard doesn't enforce a particular implementation. But typically static class members will be implemented in a similar fashion to "free" statics.

However, your observation that sizeof shouldn't be affected by static members is correct.

C ++中的静态成员的实现方式与C ++和C中的静态非成员完全相同。没有“静态成员表”。

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