关于C++builder自定义构造函数

来源:百度知道 编辑:UC知道 时间:2024/05/14 18:11:31
我自己写了一个简单的类,是用来完成一些简单功能的。
但是我发现在这个自定义类中,我想在构造函数中对某些变量初始化,但是无效,用断点调试,竟然发现程序根本就不运行到构造函数那,还报内存错误,希望大虾帮我看看,谢谢!
代码如下:

.h文件

#ifndef TestH
#define TestH
//---------------------------------------------------------------------------
#include <Classes.hpp>

//---------------------------------------------------------------------------
class TTest
{
private: // User declarations
protected:
public: // User declarations

__fastcall TTest();
int __fastcall Add(int a,int b);
int Num;
};
//---------------------------------------------------------------------------
extern PACKAGE TTest *Test;
//---------------------------------------------------------------------------
#endif

.cpp文件

#include <vcl.h>
#pragma hdrstop

#include "Test.h"
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Test=new TTest;
Edit1->Text=IntToStr(Test->Add(10,10));
delete Test;
}

你需要把c++再学学

你没有创建TTest类的实例。
Test = new TTest();
之后别忘记
delete Test;