【发布时间】:2020-01-13 20:09:42
【问题描述】:
我有一个CDateTime 类,方法如下:
CDateTime& operator=(const COleDateTime& datetime)
{
SetDateTime(&datetime);
return *this;
}
但它似乎不起作用。
谁能告诉我我错过了什么?
【问题讨论】:
标签: c++ operator-overloading assignment-operator
我有一个CDateTime 类,方法如下:
CDateTime& operator=(const COleDateTime& datetime)
{
SetDateTime(&datetime);
return *this;
}
但它似乎不起作用。
谁能告诉我我错过了什么?
【问题讨论】:
标签: c++ operator-overloading assignment-operator
您正在初始化,而不是分配 dtStart 和 dtEnd 变量。为了使初始化工作,你需要这个构造函数:CDateTime(const COleDateTime& datetime)。
或者,如果CDateTime有默认构造函数,你可以将初始化拆分为声明和赋值:
CDateTime dtStart; dtStart = dlg.m_dtStartDate;
【讨论】: