[C++] 智能指针的引用计数如何实现?—— 所有该类的对象共享静态类成员变量

问:智能指针可以对指针的引用数量进行计数,一个智能指针释放时,别的智能指针怎么知道的?

这是一个脑筋急转弯题。。。。

不像普通的变量,静态成员变量是被所有类对象共享的,不同的对象可以访问对方的该静态成员变量,因此静态成员变量和类对象并没有联系。

The static keyword has another meaning when applied to global variables -- it gives them internal linkage (which restricts them from being seen/used outside of the file they are defined in). Because global variables are typically avoided, the static keyword is not often used in this capacity.
Unlike normal member variables, static member variables are shared by all objects of the class.Static members are not associated with class objects

猜你喜欢

转载自www.cnblogs.com/dylanchu/p/11616369.html