I've got the following code:
enum nums {
a
};
class cls {
public:
cls( nums );
};
void function()
{
cls( a );
}
当我尝试使用gcc编译时,出现以下错误:
test.cpp: In function ‘void function()’:
test.cpp:12:10: error: no matching function for call to ‘cls::cls()’
test.cpp:12:10: note: candidates are:
test.cpp:7:3: note: cls::cls(nums)
test.cpp:7:3: note: candidate expects 1 argument, 0 provided
test.cpp:5:7: note: cls::cls(const cls&)
test.cpp:5:7: note: candidate expects 1 argument, 0 provided
make: *** [test] Error 1
如果我用以下代码替换该函数:
void function()
{
cls name( a );
}
然后一切正常。如果我使用带有两个参数的构造函数,也可以正常工作。如果我在构造函数中添加“explicit”,则无法正常工作。
我知道gcc以某种方式解析它,将其定义为类型为“cls”的变量,并将其命名为“a”,但我对定义变量的这种语法并不熟悉。在我看来,这是一个语句,定义了一个匿名临时变量,其类型为cls,将“a”作为参数传递。
使用gcc 4.6.3编译。
有什么见解吗?
谢谢, Shachar