简体   繁体   English

赋值运算符给出“没有合适的用户定义的转换”错误

[英]Assignment operator gives 'no suitable user-defined conversion' error

I have a CDateTime class with the following method: 我有一个使用以下方法的CDateTime类:

CDateTime& operator=(const COleDateTime& datetime)
{
    SetDateTime(&datetime);
    return *this;
}

But it doesn't appear to be working. 但是它似乎没有用。

在此处输入图片说明

Can someone tell me what I missed? 有人可以告诉我我错过了什么吗?

You are initializing, not assigning, dtStart and dtEnd variables. 您正在初始化而不是分配dtStartdtEnd变量。 To make the initialization work, you need this constructor: CDateTime(const COleDateTime& datetime) . 为了使初始化CDateTime(const COleDateTime& datetime) ,您需要以下构造函数: CDateTime(const COleDateTime& datetime)

Or, if CDateTime has default constructor, you can split the initialization into declaration and assignment: 或者,如果CDateTime具有默认构造函数,则可以将初始化分为声明和赋值:

CDateTime dtStart; dtStart = dlg.m_dtStartDate;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM