简体   繁体   中英

using static data members in inline functions

I read the following different sources,

  1. All the static data members are initialized before main() (even though the main() and static data members exist in different translation unit). – Agree
  2. The inline functions are duplicated in each source file or translation unit in which they are invoked. - Agree

It is clearly stated that static data members are initialized before main() then,

  1. What is the problem, if the inline functions access the static members?
  2. Why it is not safe to use static data members with in inline function?

Please explain with some clear examples.

There is no problem using static members and inline methods.

You can find some similar discussion about static + inline here: static variables in an inlined function

Even if it talks about static variables, the mechanism is similar.

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