gpt4 book ai didi

c++ - 如何通过另一个构造函数传递构造函数

转载 作者:太空狗 更新时间:2023-10-29 23:51:50 25 4
gpt4 key购买 nike

我有日期和时间类(class)。我正在使用公共(public)构造函数创建一个类 Onetime,但我不确定如何创建新的内联日期和时间。

schedule[0]= new Onetime("see the dentist", 
Date(2013, 11, 4),
Time(11, 30, 0),
Time(12, 30, 0));

class Onetime {
public:
Onetime( // what should I put here? )
}

最佳答案

这是标准方法

class Onetime {
std::string description;
Date date;
Time from_time;
Time to_time;

Onetime(const std::string& description,
const Date& date,
const Time& from_time,
const Time& to_time)
: description(description),
date(date),
from_time(from_time),
to_time(to_time)
{
... rest of initialization code, if needed ...
}
...
};

关于c++ - 如何通过另一个构造函数传递构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18619143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com