用 Clang 编译是下面的提示,从出错信息来看,语句 ``trade_record(code);`` 被认为和去掉括号之后的变量声明 ``trade_record code;`` 是一个含义。而第4个语句里的这个是作为表达式处理的,没有歧义。
$ clang++ -std=c++20 -o test test.cc
test.cc:13:15: warning: parentheses were disambiguated as redundant parentheses around declaration of variable named 'code' [-Wvexing-parse]
trade_record(code);
^~~~~~
test.cc:13:3: note: add enclosing parentheses to perform a function-style cast
trade_record(code);
^
( )
test.cc:13:15: note: remove parentheses to silence this warning
trade_record(code);
^ ~
test.cc:13:16: error: redefinition of 'code' with a different type: 'trade_record' vs 'int'
trade_record(code);
^
test.cc:10:7: note: previous definition is here
int code = 50;
^
1 warning and 1 error generated.
【 在 noDukkha (noDukkha) 的大作中提到: 】
: #include <iostream>
: struct trade_record {
: trade_record(){};
: ...................
--
修改:ArchLinux FROM 223.72.82.*
FROM 223.72.82.*