图解
代码解析
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
class Person
{
public:
Person()
{}
Person(char * name,int age)
{
m_Name = (char*)malloc(strlen(name) + 1);
strcpy(m_Name, name);
m_age = age;
}
Person(const Person&p)
{
m_age = p.m_age;
m_Name = (char*)malloc(strlen(p.m_Name) + 1);
strcpy(m_Name, p.m_Name);
}
~Person()
{
cout << "析构函数调用" << endl;
if (m_Name!=NULL)
{
free(m_Name);
m_Name = NULL;
}
}
char * m_Name;
int m_age;
};
void test01()
{
Person p1("敌法",10);
Person p2(p1);
}
int main(){
test01();
system("pause");
return EXIT_SUCCESS;
}