第 3 章 类和对象 3.1 类的构成 3.2 成员函数的定义 3.3 对象的定义和使用 3.4 构造函数与析构函数 3.5 对象的赋值与复制 3.6 自引用指针 this 3.7 C++ 的 string 类本章主要内容 3.1 类的构成 3.1.1 从结构体到类 3.1.2 类的构成本节主要内容 3.1.1 从结构体到类 1. 结构体的扩充 例如下面声明了一个日期结构体 : struct Date{ int year; // 年 int month; // 月 int day; // 日 };C 语言结构体一般格式如下: struct 结构名 { 数据 } ; 例 3.1 有关日期结构体的例子。#includeusing namespace std;struct Date{ // 声明了一个名为 Date 的结构体 int year; int month; int day; };int main(){ Date date1; date1.year=2010 ;// 可以在结构体外直接访问数据 year date1.month=8; // 可以在结构体外直接访问数据 month date1.day=25; // 可以在结构体外直接访问数据 day cout<