中級 › error: expected ';' after class definition の原因と直し方 › パターン2
error: expected ';' after class definition の原因と直し方
クラス定義の閉じ波括弧}の後にセミコロンを書き忘れたときに出るエラーです。
1 #include <iostream> 2 class Box { 3 public: 4 int size; 5 }_ ^ 6 int main() { 7 Box b; 8 b.size = 5; 9 std::cout << b.size << std::endl; 10 return 0; 11 }
main.cpp:5:2: error: expected ';' after class definition
空欄を埋めてコンパイル・実行を通す
クラス定義の}のあとに何も書かず次のコードが続くと、コンパイラはそこにセミコロンが無いことをエラーとして報告します。
次の問題