5

可能重复:
访问静态成员变量

我有一个符号inst,它是 class 的对象classy。我需要通过对象的符号访问这个类的静态成员。我试过inst::staticmember了,但我的 g++ 说error: ‘inst’ is not a class or namespace

我怎样才能做到这一点?

4

1 回答 1

13

您使用点:

inst.staticmember

::仅用于名称空间或类,您可能已经从编译器错误中看出。

您可以通过两种方式访问​​静态成员变量:通过classy::staticmemberwhere classyis a class 或inst.staticmemberwhere instis class instance。

于 2012-09-27T17:20:53.813 回答