【发布时间】:2010-12-08 06:31:36
【问题描述】:
假设我有这个 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 调用它吗?
(如果这有什么不同的话,我实际上在调用<ctime> 库中的time 函数时遇到了这个问题)
【问题讨论】:
标签: c++ inheritance masking