“::”的作用可以解决C++中多重继承可能出现的两异性的问题,例如:
class A
{
A(){}
public:
hello(){cout<<"hello A";}
};
class B
{
B(){}
public:
hello(){cout<<"hello B";}
};
class C: public A,public B
{
C(){}
public:
hello(){cout<<"hello C";}
};
void main()
{
C c;
c.A::hello();
c.B::hello();
c.hello();
}
如果没有::就会让编译器不知道该调用那个函数,导致编译出错,你学会了吗?