Item 26: Limiting the number of objects of a class.(More Effective C++)

你的名字 2021-11-10 00:32 274阅读 0赞

Now consider what inline means. Conceptually, it means compilers should replace each call to the function with a copy of the function body, but for non-member functions, it also means something else. It means the functions in question have internal linkage.

You don’t ordinarily need to worry about such linguistic mumbo jumbo, but there is one thing you must remember: functions with internal linkage may be duplicated within a program (i.e., the object code for the program may contain more than one copy of each function with internal linkage), and this duplication includes static objects contained within the functions. The result? If you create an inline non-member function containing a local static object, you may end up with more than one copy of the static object in your program! So don’t create inline non-member functions that contain local static data.

转载于:https://www.cnblogs.com/zhtf2014/archive/2012/03/13/2393775.html

发表评论

表情:
评论列表 (有 0 条评论,274人围观)

还没有评论,来说两句吧...

相关阅读