7.2 — Reading an error message
Read one box at a time. No rush.
Don't panic#
Error messages look scary, but they follow a pattern:
Output
main.cpp:7:18: error: 'scroe' was not declared in this scope; did you mean 'score'?main.cpp= the file.7= the line number.18= the column (how far along the line).error:= what went wrong.did you mean 'score'?= a helpful hint!
Three steps#
- Look at the first error only.
- Go to that line. Also look at the line above it.
- Read the message slowly, one word at a time.
Common messages in plain words#
| Message says | It usually means |
|---|---|
expected ';' | You forgot a semicolon (often on the line above). |
was not declared | Typo in a name, or missing #include, or used before it was made. |
expected '}' | A { has no matching }. Count your braces. |
no match for 'operator<<' | You tried to print something C++ doesn't know how to print. |
cannot convert | You gave the wrong type, like text where a number was needed. |
undefined reference | A function was declared but never written (or its file wasn't compiled). |
Warnings#
A warning is not an error. The program still builds. But warnings often point at real bugs.
Good habit
Turn on all warnings (-Wall -Wextra for g++/clang, /W4 for Visual Studio) and fix every one of them.
Tip: press ← / → to move between lessons, / to search.