鱼C论坛

 找回密码
 立即注册
查看: 1703|回复: 2

c++在一个类中内嵌了一个常类,怎么写构造函数?

[复制链接]
发表于 2014-5-25 21:28:03 | 显示全部楼层 |阅读模式
10鱼币
  1. class Employee{
  2. public:
  3. // 构造函数,使用"成员初始化器"初始化数据成员
  4. Employee(const char string_1[20], const char string_2[20], const Date&birth, const Date&hire);


  5. ~Employee(); // destructor
  6. private:
  7. string firstName;
  8. string lastName;
  9.     // 要求:出生日期、雇用日期必须声明为const,
  10. // 因为对于每个雇员,这两个属性都是不能变化的。
  11. const Date birthDate; // 这是一个date类的对象
  12. const Date hireDate;
  13. };
复制代码

请问怎么写它的构造函数?重要的是const Date birthDate;  const Date hireDate;怎么写

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2014-5-26 19:11:12 | 显示全部楼层
用Employee(const char string_1[20], const char string_2[20], const Date&birth, const Date&hire):birthDate(birth),hireDate(hire){ }即可

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2015-8-10 11:56:33 | 显示全部楼层
{:1_1:}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-20 17:07

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表