#include<iostream>
using namespace std;
class der
{
public:
void fun()
{
cout << "Good";
}
};
int main()
{
der a;
a.der::fun(); // method 1
a.fun(); // method 2
return 0;
}
我知道,::
用于访问命名空间或嵌套类的内容...但是我在代码中提到的方法 1 和方法 2 之间的主要区别是什么?两者都工作正常...
谢谢。
最佳答案
a.der::fun();
仅使用显式类作用域。这对您的情况没有任何影响。
有趣的是,如果您想显式调用基类函数,该函数被 der
公开继承。
关于c++ - 点和范围解析运算符类对象之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30012892/