I started getting the error, "error C2059: syntax error : 'default argument'" for a line of code that declared a function with a string argument that was given a default parameter. This was obviously a bit frustrating, as the error message was not exactly enlightening (I know it's a 'default argument'!), and the exact declaration would work elsewhere.
After shifting about the declaration a bit, I found its position in its containing class actually had an effect. Narrowing it down, I found that I was declaring a different function somewhat erroneously, by including a semicolon after one of its default parameters. The compiler seemed perfectly fine with that, which seemed a bit odd. I investigated a bit more, and came up with the following test case to try to figure out the essence of what was going on:
enum TestEnum1
{
TEST_ONE
};
class TestClass
{
public:
enum TestEnum2
{
TEST_TWO,
TEST_THREE,
TEST_FOUR
};
void Func1( int iParm = TEST_ONE; ); // additional semicolon here
void Func2( std::string strParm = "" );
};
As the code above stands, Func2 will produce the compilation error I mentioned above. If I move Func2 above Func1, then everything compiles fine.
If I switch the default parameter in Func1 to an explicit number or use an enum declared within TestClass, then I get an expected syntax error for that line.
So essentially, the strange thing seems to be that if I set a default parameter's value to an enum not defined directly in the current class and am a little too semicolon-happy, the compiler will ignore the syntax error, until some other seemingly-unrelated thing finally causes the parser to die in a very inscrutable way.
Am I just missing something completely? Is this expected behavior? I'm hesitant to go calling it a bug in the compiler, certainly, but this hardly seems correct. If it's just me misunderstanding something about the standard, then I'd like to know where I'm wrong.