calling a global function with a class method with the same declaration

Abruzzo Forte e Gentile picture Abruzzo Forte e Gentile · Aug 22, 2011 · Viewed 16.6k times · Source

I would like to wrap a C library within a C++ class. For my C++ class I also would like to have the same declaration used by these C function: is it possible to do that?

If for example I have the case below how would it be possible to distinguish the C-function from the C++ one? I would like to call the C one off course.

 extern int my_foo( int val ); //

 class MyClass{
    public:
    int my_foo( int val ){
           // what to write here to use
           // the C functions?
           // If I call my_foo(val) it will call
           // the class function not the global one
    }
 }

Answer

Adam Rosenfield picture Adam Rosenfield · Aug 22, 2011

Use the scope resolution operator :::

int my_foo( int val ){
    // Call the global function 'my_foo'
    return ::my_foo(val);
}