c++ - 调用成员 C++ 函数但 C 函数具有相同的名称

标签 c++ c function namespaces member

我正在使用 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/

相关文章:

php - 从函数中回显 PHP 变量的宽度 : Style

c++ - hash_map : why it defines less, 而不是 equal_to

c++ - 函数属性应该放在哪里?

c - 在 C 中调整数组大小

C - 分配动态数组后无法接受输入

javascript - Java math.random 不会在函数内随机化?

c++ - 32/64 位构建之间的字符串格式方法一致性

c++ - 这是我的 Node 结构的正确析构函数吗?

c - 获取两个不同分隔符之间的标记

c - 为什么这个静态函数有三个前缀?