Code Fix

中級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

空欄を埋めてコンパイル・実行を通す

広告
広告スロット(未設定)

error: expected ';' after class definition の原因と直し方

C++特有の落とし穴で、if文や関数定義の}にはセミコロンは要りませんが、クラスや構造体の定義には必要です。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)