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