How can I call the masked function in C ++?

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 need to inherit from a class Parent

in order to customize some functionality within the framework. However, the class is Parent

masking the global exampleFunction

which I want to call. Is there any way I can call this from myFunction

?

(I actually have this problem with calling a function time

in a library <ctime>

, if that matters)

+2


source to share


1 answer


Follow these steps:

::exampleFunction()

      

::

will refer to the global namespace.



If you are #include <ctime>

, you should be able to access it in the namespace std

:

std::time(0);

      

To avoid these problems, put everything in namespaces and avoid global directives using namespace

.

+17


source







All Articles