**1.下列程序运行中,stu0103和stu0104的地址和stu0102、stu0101的地址相差比较大。请问为什么,分别存在什么区?
2.请问加号运算符重载中是否调用了拷贝构造函数?
**
#include<iostream>
#include<string>
using namespace std;
class Student_t {
public:
Student_t():Student_t("Lilei",18) {}
Student_t(const std::string name,const int age,const int high = 175) :name(name), age(age), high(high) {
** //学生人数++**
number_of_stu++;
}
//成员加号运算符重载
Student_t operator+(Student_t& stu);
private:
std::string name;//学生姓名
int age;//年龄
int high;//身高
static int number_of_stu;//学生人数
};
extern std::ostream& operator<<(std::ostream& os, const
Student_t& stu);
//成员加号运算符重载
Student_t Student_t::operator+(Student_t& stu) {
return Student_t(this->name + stu.name, this->age + stu.age,this->high + stu.high);
}
int main()
{
//堆空间对象
Student_t* stu0101 = new Student_t("C",10);
Student_t* stu0102 = new Student_t("X",9);
Student_t* stu0103 = &(*stu0101 + *stu0102);
cout << *stu0103 << endl;
Student_t* stu0104 = &(*stu0101 + *stu0103);
cout << *stu0104 << endl;
cout << stu0101 << " " << stu0102 << " " << stu0103 << " "<< stu0104<<endl;
system("pause");
return 0;
}