2010-01-17 97 views
1

是否有一種簡單的方法可以在類之外調用某個類方法中的函數,其名稱與類中的一個方法具有相同名稱。從類之外調用類方法中的函數名稱與類中的一個方法具有相同的名稱

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

在此先感謝

回答

6

要引用一個名字當前類之外,使用空命名空間操作::

void A::a() 
{ 
    ::a(); // calls the outside one 
} 
相關問題