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

:类域是什么作用解决方法

2012-04-30 
::类域是什么作用备战C++二级,结果看到这道题让我蒙了#includeiostream.hint a10class C0{public:C0()

::类域是什么作用
备战C++二级,结果看到这道题让我蒙了

#include<iostream.h>
int a=10;
class C0
{
public:
C0()
{
a = b= 0;
}
void print()
{
/********found********/
cout<<a<<b<<endl;
}
void fun(int a)
{
/********found********/
this->a += a;
}
void fun2()
{
/********found********/
a += ::a;
}
private:
int a,b;
};
void main()
{
C0 obj;
obj.fun(5);
obj.print();
obj.fun2();
obj.print();
}
要求的结果是要输出50和150,红色的地方,我用了a=a*3,答案却是a += ::a,完全看不明白::的作用,求各位高手解答

[解决办法]
全局或父类
[解决办法]

探讨

那如果我想要调用父类,是不是在这个类域符号前加父类名就可以了?

热点排行