开发者

Invoke function within class method from outside the class with name the same like one method in class has

开发者 https://www.devze.com 2022-12-16 10:40 出处:网络
Is there a simple way to invoke the function within some class method from outside the cla开发者_如何学Pythonss with name the same like one method in class has.

Is there a simple way to invoke the function within some class method from outside the cla开发者_如何学Pythonss with name the same like one method in class has.

I have 3 different examples.

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, 
    }
};

Thanks in advance


To reference a name outside the current class, use an empty namespace operator ::.

void A::a()
{
    ::a (); // calls the outside one
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号