【发布时间】:2012-09-27 17:19:26
【问题描述】:
我有一个符号inst,它是classy 类的对象。我需要通过对象的符号访问这个类的一个静态成员。我试过inst::staticmember,但我的g++说error: ‘inst’ is not a class or namespace。
我该怎么做?
【问题讨论】:
标签: c++ class static-members
我有一个符号inst,它是classy 类的对象。我需要通过对象的符号访问这个类的一个静态成员。我试过inst::staticmember,但我的g++说error: ‘inst’ is not a class or namespace。
我该怎么做?
【问题讨论】:
标签: c++ class static-members
你使用点:
inst.staticmember
:: 仅用于命名空间或类,您可能已经从编译器错误中看出。
您可以通过两种方式访问静态成员变量:通过classy::staticmember,其中classy 是一个类,或者通过inst.staticmember,其中inst 是一个类实例。
【讨论】: