C++不知道的只是二——作用域分辨的作用

来源:互联网 发布:软件大全网站 编辑:程序博客网 时间:2024/04/28 12:12

  “::”的作用可以解决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();

}

如果没有::就会让编译器不知道该调用那个函数,导致编译出错,你学会了吗?



0 0