Reading errors
can be simple, but some errors can be damn right cryptic. When reading an error, highlight the important parts of the message and go from there. For example:
d:\repository\c++\test projects\console\console\console.cpp(20): error C2143: syntax error : missing ')' before '{'
This can be a bit of an eye-strainer for a beginner, but if your strip away the unnecessary information, you're left with this:
console\console.cpp(20): missing ')' before '{'
This is far more simpler to parse. From this information alone, I know the folder, file, line, and the error itself. Lets do the latter again, this time, with a more complex error. To start, I'll post this little code snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
template< typename T >
void Function( T &X )
{
std::cout << X << std::endl;
}
// Create a simple structure.
struct Simple
{
int A;
char B;
} SSimple;
// Call the function.
Function< Simple >( SSimple );
|
Clearly, this code has many issues with it. However, this was made to generate a complex template error.
When I called this function, I received this error:
d:\repository\c++\test projects\console\console\console.cpp(19): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'SSimple' (or there is no acceptable conversion)
At first, a beginner would be like:
WTF is this cryptic nonsense? As I said before, breaking the error down is the best thing to do. So, if I strip this error message down, I get:
console\console.cpp(19): binary '<<' : no operator found which takes a right-hand operand of type 'SSimple'
This message is telling me that the operator
<< has no overloaded version that takes an instantiation of
Simple as an operand. Since I stripped away the directory, the message instantly became more clear. Now, to do the actual parsing of this error message. This message can be divided into 2 parts, which are:
Section A)
binary '<<'
Section B)
no operator found which takes a right-hand operand of type 'SSimple'
Section A indicates the operator that is causing the problem. This narrows the scope to that operator on the stated line.
Section B is the actual error. Reading this section reveals the word
operand. An operand, in a nutshell, is an argument that is used either on the left or right-hand side of an operator. An operand can be anything, as long as it's supported by that operator. The "
right-hand operand" part indicates that the operand I passed to the right-hand side of the operator
<< is not supported. So, there's my error.
Need a more complex example?
Wazzak