从类外部调用类方法中的函数,其名称与类中的一个方法相同

kok*_*ing 1 c++

是否有一种简单的方法可以从类外部调用某个类方法中的函数,其名称与类中的一个方法相同.

我有3个不同的例子.

void a () { // outside the class
}

class A {
    // example 1, the same names
    void a() {
       a (); // but the outside one, 
    }
    // example 2, different list of arguments
    void a(int x) {
       a (); // but the outside one, 
    }
    // example 1, different names
    void b () {
       a (); // but the outside one, 
    }
};
Run Code Online (Sandbox Code Playgroud)

提前致谢

Mar*_*som 6

要引用当前类之外的名称,请使用空名称空间运算符::.

void A::a()
{
    ::a (); // calls the outside one
}
Run Code Online (Sandbox Code Playgroud)