2

假设我有这个 C++ 代码:

void exampleFunction () { // #1
    cout << "The function I want to call." << endl;
}

class ExampleParent { // I have no control over this class
public:
    void exampleFunction () { // #2
        cout << "The function I do NOT want to call." << endl;
    }
    // other stuff
};

class ExampleChild : public ExampleParent {
public:
    void myFunction () {
        exampleFunction(); // how to get #1?
    }
};

我必须从Parent类继承才能自定义框架中的某些功能。但是,Parent该类掩盖了exampleFunction我要调用的全局。有什么方法可以调用它myFunction吗?

(如果这有什么不同,我实际上在调用库中的time函数时遇到了这个问题)<ctime>

4

1 回答 1

17

请执行下列操作:

::exampleFunction()

::将访问全局命名空间。

如果你#include <ctime>,你应该能够在命名空间中访问它std

std::time(0);

为避免这些问题,请将所有内容都放在命名空间中,并避免使用全局using namespace指令。

于 2009-10-20T08:45:13.267 回答