为什么下面的代码不能在g ++(C++ 14),MSVC(C++ 14)或ARM(C++ 03)下编译?
命名的Error实例调用整数构造函数,但匿名的Error实例无法解析.
class Error
{
public:
Error(int err) : code_(err) {}
const int code_;
};
enum Value
{
value_1
};
int main()
{
// compiles
Error e(value_1);
// does not compile under G++, ARM, or MSVC
Error(value_1);
}
Run Code Online (Sandbox Code Playgroud)
G ++下的示例错误:( Coliru链接)
g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
main.cpp: In function 'int main()':
main.cpp:19:18: error: no matching function for call to 'Error::Error()'
Error(value_1);
^
main.cpp:4:5: note: candidate: Error::Error(int)
Error(int err) : code_(err) {} …
Run Code Online (Sandbox Code Playgroud)