首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于静态成员变量的有关问题

2012-03-30 
关于静态成员变量的问题#include iostreamusingnamespacestdclassAA{public:AA(int a9):num(a){}void

关于静态成员变量的问题
#include <iostream> 
using namespace std; 
class AA 

public: 
AA(int a=9):num(a){}; 
void show() 

cout <<num <<endl; 

private: 
static AA refAA; 
int num; 

}; 
AA AA::refAA(2);   //静态成员初始化 
int main() 

AA::refAA.show(); 
return 0;

请高手指教下,这里哪里出问题啦。请详细皆大笑,我还是新手,谢谢啦~

[解决办法]
“AA::refAA”: 无法访问 private 成员(在“AA”类中声明)

自己要看编译出来的错误信息!
[解决办法]

C/C++ code
#include <iostream>using namespace std;class AA{      public:       AA(int a=9):num(a){};       void show()       {            cout <<num <<endl;            }       private:        static AA refAA;        int num;};AA AA::refAA(2);int main(){      //AA::refAA.show();    system("pause");    return 0;} 

热点排行