#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string.h>
using namespace std;
class MyString
{
public:
MyString()
{
cout << "默认构造" << endl;
}
MyString(const char* str)
{
m_Str = (char*)malloc(strlen(str) + 1);
strcpy(m_Str, str);
}
explicit MyString(int a)
{
m_Size = a;
}
MyString(const MyString & p)
{
m_Size = p.m_Size;
m_Str = (char*)malloc(strlen(p.m_Str) + 1);
strcpy(m_Str, p.m_Str);
cout << "拷贝构造" << endl;
}
~MyString()
{
if (m_Str != NULL)
{
free(m_Str);
m_Str = NULL;
}
cout << "析构函数" << endl;
}
char* m_Str;
int m_Size;
};
void test01()
{
MyString MyStr("GameLoL");
MyString MyStr2(10);
cout << "m_Str :" << MyStr.m_Str << endl;
cout << "m_Size:" << MyStr.m_Size << endl;
}
int main()
{
test01();
system("pause");
return EXIT_SUCCESS;
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string.h>
using namespace std;
class MyString
{
public:
MyString()
{
cout << "默认构造" << endl;
}
~MyString()
{
cout << "析构函数" << endl;
}
char* m_Str;
int m_Size;
};
void test01()
{
MyString* MyStr = new MyString;
delete MyStr;
}
void test02()
{
MyString* pArray = new MyString[10];
delete [] pArray;
}
int main()
{
test02();
system("pause");
return EXIT_SUCCESS;
}