Possible Duplicate:
A function-definition is not allowed here before ‘{’
I would like to share this bug I did in my code, one of the hard to find ones:
#include <iostream>
void StartNuclearWar() {
std::cout << "War in progress..." << std::endl;
}
int main()
{
int a = 0;
// Get activation codes from C:\codes\
a = 1;
if(a == 0) {
StartNuclearWar();
}
}
Where is it?
The bug is in the comment: for us the final \ character represents a directory, for the compiler it means that the following line is part of the current line. Of course every developer knows that, but in this case this detail is quite well hidden.
Nice gotcha, MSDN calls this line splicing.
All lines ending in a backslash (
\
) and immediately followed by a newline character are joined with the next line in the source file forming logical lines from the physical lines. Unless it is empty, a source file must end in a newline character that is not preceded by a backslash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With