動作環境
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で実装すれば、こういう間違いは起きない。