gcc: error: request for member ‘readable‘ in ‘*(char*)(& buf)‘, which is of non-class type ‘char‘

解释

https://ask.csdn.net/questions/7757934
汉语解释是:

'*(char*)(& buf)'这个地址指向的char数组请求“readablebytes”这个成员,但是这个地址的数据类型确实非类类型的char数据。没有readablebytes这个成员函数所以导致编译错误。
error: request for member 'readablebytes' in '*(char*)(& buf)', which is of non-class type 'char'

可能的原因

buf变量用错了类型。

代码示例

下面是一个宏展开导致的buf变量,出现覆盖的情况,外层传入的buf参数,被本地的char buf[] 覆盖,导致编译错误。

LOG_INFO(“%s abcd”, buf->readablebytes());

#define LOG_INFO(logmsg, …)
do
{
char buf[1024] = {0};
snprintf(buf, 1024, logmsg, ##VA_ARGS); /// 这里编译出错。
}

猜你喜欢

转载自blog.csdn.net/qq_36428903/article/details/125812980