访问静态成员变量 [英] accessing static member variables
本文介绍了访问静态成员变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用点符号访问类的静态成员变量,还是应该坚持使用双冒号的访问运算符?
Can I access static member variables of a class using dot notation or should I stick in access operator which is double colon?
推荐答案
p>如果你有一个实例变量,你可以使用点运算符访问静态成员,如果可访问的话。
If you have an instance variable you may use dot operator to access static members if accessible.
#include <iostream>
using namespace std;
class Test{
public:
static int no;
};
int Test::no;
int main(){
cout << "\n" << Test::no;
Test::no=100;
Test a;
cout << "\n" << a.no;
return 0;
}
这篇关于访问静态成员变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文