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