7.2 — Reading an error message

📘 Chapter 7⏱ about 1 min read✍️ Beginner friendly
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#

  1. Look at the first error only.
  2. Go to that line. Also look at the line above it.
  3. Read the message slowly, one word at a time.

Common messages in plain words#

Message saysIt usually means
expected ';'You forgot a semicolon (often on the line above).
was not declaredTypo 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 convertYou gave the wrong type, like text where a number was needed.
undefined referenceA 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.

Finished reading? Tick it off. Your progress is saved in this browser.

Tip: press ← / → to move between lessons, / to search.