0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ Builder XE4 > Error > E2251 基底クラス 'TForm' を初期化するデフォルト コンストラクタが見つからない > 対処

Last updated at Posted at 2018-11-20
動作環境
C++ Builder XE4

Error

エディタで一から実装したとき、コンストラクタの作成部分の実装で下記のエラーが出た。

[bcc32 エラー] Unit1.cpp(13): E2251 基底クラス 'TForm' を初期化するデフォルト コンストラクタが見つからない
  詳細な解析情報
    Unit1.cpp(13): 構文解析対象:  _fastcall TForm1::TForm1(TComponent *)

実装 (簡略版)

Unit1.h
//---------------------------------------------------------------------------

# ifndef Unit1H
# define Unit1H
//---------------------------------------------------------------------------
# include <System.Classes.hpp>
# include <Vcl.Controls.hpp>
# include <Vcl.StdCtrls.hpp>
# include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE で管理されるコンポーネント
private:	// ユーザー宣言
public:		// ユーザー宣言
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
# endif
Unit1.cpp
//---------------------------------------------------------------------------

# include <vcl.h>
# pragma hdrstop

# include "Unit1.h"
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
{
}
//---------------------------------------------------------------------------

間違い

__fastcall TForm1::TForm1(TComponent* Owner)
{
}

正解

__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}

TForm(Owner)からの継承?を記載忘れのために「デフォルトコンストラクタが見つからない」ということのようだ。

IDEで実装すれば、こういう間違いは起きない。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?