this指针
#include<iostream>
#include<string>
using namespace std;
class CStudent
{
char* name;
public:
CStudent(const char* name)
{
this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
}
void getName()
{
cout << (*this).name << endl;
}
CStudent *fun()
{
return this;
}
CStudent fun1()
{
return *this;
}
~CStudent()
{
cout << "析构函数" << endl;
if (name != NULL)
{
delete[]name;
name = NULL;
}
}
};
int main()
{
CStudent stu("aaaa");
stu.getName();
stu.fun()->getName();
stu.fun1().getName();
CStudent* p = stu.fun();
cout << &stu << endl;
cout << p << endl;
return 0;
}