I've got the following code:
enum nums {
a
};
class cls {
public:
cls( nums );
};
void function()
{
cls( a );
}
When I try to compile it with gcc, I get the following error:
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
If I replace the function with this:
void function()
{
cls name( a );
}
then everything works. It also works if I use a constructor with two arguments. It does not work if I add "explicit" to the constructor.
I get that gcc is somehow parsing this as defining a variable of type "cls" with the name "a", but I am not familiar with such a syntax for defining variables. To my eyes, this is a statement defining an anonymous temporary variable of type cls, passing "a" is the parameter.
Compiled with gcc 4.6.3.
Any insights?
Thanks, Shachar