使用具有相同声明的类方法调用全局函数

Abr*_*ile 32 c++ gcc word-wrap

我想在C++类中包装一个C库.对于我的C++类,我也希望这些C函数使用相同的声明:是否可以这样做?

例如,如果我有以下情况,如何区分C函数和C++函数?我想打电话给C一个.

 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
    }
 }
Run Code Online (Sandbox Code Playgroud)

Ada*_*eld 54

使用范围解析运算符:::

int my_foo( int val ){
    // Call the global function 'my_foo'
    return ::my_foo(val);
}
Run Code Online (Sandbox Code Playgroud)


Alo*_*ave 7

使用合格的名称查找

::my_foo(val);
Run Code Online (Sandbox Code Playgroud)

这告诉编译器要调用全局函数而不是本地函数.


nob*_*ody 6

::my_foo(val);
Run Code Online (Sandbox Code Playgroud)

应该这样做.