我正在使用 C 库
#define read _io_read
但我有一个 C++ 类,它继承了一个成员函数“read”。 我试图从另一个成员函数调用成员函数但是 编译器认为我正在尝试在全局范围内调用 C 函数。
我尝试了以下方法
//header
namespace myNameSpace{
class B : public A{
int read();
int do_read();
}
}
//cpp
using namespace myNameSpace;
int B::read(){
//other code needed
_io_read();
}
int B::do_read(){
this.read(); // here is where compiler resolves to _io_read
}
这附近有没有?我宁愿不重命名基类 A 的读取函数,因为我无法更改不属于我的代码。
TIA
最佳答案
你可以使用:
int B::do_read(){
#undef read
this.read(); // here is where compiler resolves to _io_read
#define read _io_read
}
关于c++ - 调用成员 C++ 函数但 C 函数具有相同的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33509597/