#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
// 存
void setname(string s){ name = s;}
void setage(int y){age = y; }
void setaddress(string add){address = add;}
// 取
string getname(){return name;}
int getage(){return age;}
string getaddress(){return address;}
Student & show()
{
cout<<"调用成员函数show-------"<<endl;
cout<<"姓名: "<<name<<" --- 年龄: "<<age<<" ---- 住址: "<<address<<endl;
return *this;
}
//-- 引入构造函数:初始化成员,与类同名,没有返回值
Student(string name,int age,string address)
{
this->name = name; this->age = age; this->address = address;
cout<<this->name<<":调用构造函数---"<<endl;
cout<<"姓名: "<<this->name<<" --- 年龄: "<<this->age<<" ---- 住址:
详细解决方案
C++,类的构造与析构函数,进栈出栈 以及堆上的执行 顺序 语法练习
热度:58 发布时间:2024-01-19 15:37:26.0
相关解决方案