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