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