views:

128

answers:

1

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)

+17  A: 

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.

GMan
+1 for this short and detailed answer
fmuecke
or `::std::time(0)` of course, to access the std version without any ambiguity
jalf