•在成员函数中,可以将this指针当参数传递,也可以返回this指针,或返回通过this指针拿到的对象
/*
成员变量是别的类的对象
*/
#include <iostream>
using namespace std;
//日期类
class Date {
int year,month,day;
public:
//构造方法
Date(){
cout << "Date() " << endl;
}
//有参
Date(int _y,int _m,int _d):year(_y),month(_m),day(_d){
}
//
void setValue(int year,int month,int day){
this -> year = year;
this -> month = month;
this -> day = day;
}
};
//员工类
class Employee{
string name;//C++的字符串
int age;
Date bir;
public:
Employee (string name,int age){
cout << "员工的构造方法" << endl;
//创建对象的最后一步是调用构造方法。只要开辟了内存空间,这个对象就有了,也就是说在构造方法里面有this指针
this->name = name;
this->age = age;