类的构造、析构

时间:2022-05-28 19:31:18
/*
* main.cpp
*
* Created on: 2016-10-20
* Author: llf05
*/
# include <iostream>
using namespace std;

class Clock //封装 类中可以包含类
{
public: //公有成员
Clock(int a = 5, int b = 6, int c = 7) //构造函数
{
cout << "调用构造函数" << endl;
hour = a;
min = b;
sec = c;
};
void SetTime(int nhour, int nmin, int nsec); //SetTime showtime 外部接口
void ShowTime() //class 内实现 inline函 数
{
cout << hour << ":" << min << ":" << sec << endl;
};

//对象生存期结束的时候,系统会自动调用析构函数, 编译器会自动生成一个缺省的析构函数
~Clock()
{
cout << "调用析构函数" << endl; //整个程序结束时调用构造函数
};
private://子类也不能访问 私有成员
int hour, min, sec;
protected: //保护型成员
};

int main()
{
Clock a(1, 2, 3); //类在定义时可以初始化

a.ShowTime();
cout << "退出主函数" << endl;

return 0;
}


<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhIAAABqCAYAAADp07g6AAAY60lEQVR4Ae2dv4/j2JHHSzcDw/4LDAMGnHTfeuAdwIAj9fwF3Zhgog5nMync7mCym6gvm0CasJXthB11sJbsP2C6HRhw0AYGe1Jg4O5sBw4OtgFHCx6KZEnF4vtBUiKp1nwF7L7H96rq1fvwkVV8onoGv//rH5Jf/fiX5Pr89nd/pl/85O/09OkT+tEPf+ASSdv+8c9/0U9/9nNvPzpAAASaEfj++++bKfao9eTJkx5Hx9AgAAJdE3ja9YAYDwRAoDoBBOXqrCAJAiDQD4F/62dYjAoCIAACIAACIHAIBJBIHMJZxBxAAARAAARAoCcCn2cisZrSyeCEpqueqPOwizENTqa0excWNB6MadHj1PZu6NZY791M4VBjAuq62fX9Ydf2Gs/xsSqqc0O6zvNZ0fRkQIPBgMaP4qaX+fs4fK2+Xj7PRKI6H0iCwEERWIyzm+6gcCfjm3PezmWhL59+Ggx1glpBpxVyeeBw+djKePtjdH3uog8gsXPD/a4HKU87n/vomLvg5Bk/YHo1fU2Xz+eUJAldn7KgnntxjqvpSZpwcNKR/peuId+Ymw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