Common errors
Compiler errors (“was not declared in this scope”, “no match for operator”), linker errors, and crashes.
Runs in Zerethon IDE · C++ (GCC 14)
Official C++ documentation ↗
g++ messages start with the file and line. Template errors can be long: read the first error: line, then look for the line in your own file.
error: 'x' was not declared in this scope— a typo, a variable from another block, a missing#include, or a missingstd::.error: no matching function for call to …— the argument types do not fit any version of the function; the notes below list what was tried.error: no match for 'operator<<'— printing a type that has no<<(for example a wholestd::vector); print its elements in a loop.undefined reference to …— declared but never defined: a missing.cppfile, or one whose name starts withmain/test_.terminate called after throwing an instance of 'std::out_of_range'— an uncaught exception, here from.at()orstd::stoi.g++: internal compiler error: File size limit exceeded— the compiler's intermediate output for one source file is over the run's 1 MB file-size limit. It happens with several heavy headers in one file (<regex>and<format>together, for example). Move part of the code into another.cppfile: each file is compiled separately.- Exit code 139 (signal 11, segmentation fault) — an index past the end with
[], a null or dangling pointer, or a reference to a destroyed object.
main.cpp
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
int main() {
std::vector<std::string> values{"10", "x", "7"};
int total = 0;
for (const auto& v : values) {
try {
total += std::stoi(v);
} catch (const std::invalid_argument&) {
std::cout << "skipped " << v << '\n';
}
}
std::cout << "total: " << total << '\n';
}
Output
skipped x total: 17