[英]assignment of read-only location of non const variable
为什么下面的宏失败
#define XML_TEST(K, V) K = V;
struct teststruct {
teststruct() {
TEST("x_", 10);
}
int x_;
};
这不会编译并出现以下错误:
test.h:30: error: assignment of read-only location ‘"x_"’
#define XML_TEST(K, V) K = V;);
简单地做
teststruct() {
x_ = 10;
} ^
工作正常。 我也没有在这里看到任何常量。 有人知道我在这里缺少什么吗?
TEST("x_", 10);
将处理成
"x_" = 10;
这绝对是一个问题,因为我们要分配给常量字符串。 我相信你的意思
TEST(x_, 10);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.