Reputation: 5908
Let's say I have this C++ code:
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?
}
};
I have to inherit from the Parent
class in order to customize some functionality in a framework. However, the Parent
class is masking the global exampleFunction
that I want to call. Is there any way I can call it from myFunction
?
(I actually have this problem with calling the time
function in the <ctime>
library if that makes any difference)
Upvotes: 2
Views: 1152
Reputation: 503855
Do the following:
::exampleFunction()
::
will access the global namespace.
If you #include <ctime>
, you should be able to access it in the namespace std
:
std::time(0);
To avoid these problems, place everything in namespaces, and avoid global using namespace
directives.
Upvotes: 17