我想在 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
}
}
最佳答案
使用 scope resolution operator ::
:
int my_foo( int val ){
// Call the global function 'my_foo'
return ::my_foo(val);
}
关于c++ - 使用具有相同声明的类方法调用全局函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7149922/