When we are writing C++ programs, the compiler is our first line of defense against errors.
There are two types of compile-time errors:
- Syntax errors: Errors that occur when we violate the rules of C++ syntax.
- Type errors: Errors that occur when there are mismatch between the types we declared.
Some common syntax errors are:
- Missing semicolon
- Missing closing parenthesis
), square bracket
], or curly brace
Some common type errors are:
- Forgetting to declare a variable
- Storing a value into the wrong type
Here’s an example of a compile-time error message:
The compiler will tell us where (line number) it got into trouble and its best guess as to what is wrong.
Try compiling the code and find the compile-time error in millionaire.cpp.