#include "Ctest.h"
#include "Tstr.h"
using namespace std;
void main()
{
Ctest testA=3;
testA=4;
testA=Ctest(8);
Ctest testB=testA;
Tstr bb("mydemo");
//char* str = "";
char* result = bb.getP();
cout<<"cur str is:"<<result<<endl;
}
#include <iostream.h>
#include <string.h>
class Tstr
{
private:
char *p;
public:
Tstr(const char* in);
char* mstr(const char* Input);
char* getP();
~Tstr();
};
#include "Tstr.h"
Tstr::Tstr(const char* in)
{
cout<<"begin"<<endl;
p = new char(strlen(in)+1);
strcpy(p,in);
}
char* Tstr::mstr(const char* input)
{
p = new char(strlen(input)+1);
strcpy(p,input);
return p;
}
char* Tstr::getP()
{
return p;
}
Tstr::~Tstr()
{
/*if(p!=NULL)
{
delete p;
}*/
cout<<"call funcation"<<endl;
}
当我在析构函数中DELETE P 或把上面析构函数中注释取消的时候,都会有一个运行时错误??
请给出详细解答,编写平台VC 6.0