奇怪的 : caerror C2440: 'initializing'nnot convert

ruoge2007 2010-08-11 10:05:08
先贴上代码:

xui_logComboBox xLogCb=CResKeeper::m_logComboBox;//此处出现caerror C2440: 错误
xui_logComboBox xLogCbA, xLogCbB;
xLogCbA = xLogCbB;//此处无此错误
////////////////////////////////////////////////////////////
//.h
static xui_logComboBox m_logComboBox;
//.cpp
xui_logComboBox CResKeeper::m_logComboBox;
//define 实现 = 操作符
struct xui_logComboBox
{
enum xField
{
CB_EDIT = 1 << 1,
CB_BTN = 1 << 2,
CB_ITEMBACK = 1 << 3,
CB_LISTITEM = 1 << 4,
};
struct cbEdit
{
LOGFONT logFont;
COLORREF clrText;
COLORREF clrTL;
COLORREF clrRB;
int nBdWidth;
cbEdit & operator = ( cbEdit & src)
{
logFont = src.logFont;
clrText = src.clrText;
clrTL = src.clrTL;
clrRB = src.clrRB;
nBdWidth = src.nBdWidth;
return *this;
}
};
struct cbBtn
{
enum xField
{
CBB_FILL = 1 << 1,
CBB_PIC = 1 << 2,
};
UINT nMask;
COLORREF clrTL;
COLORREF clrRB;
COLORREF clrBg;
BOOL bLR;
SIZE btnSize;
CString strPicture;
cbBtn & operator = ( cbBtn & src)
{
nMask = src.nMask;
clrTL = src.clrTL;
clrRB = src.clrRB;
clrBg = src.clrBg;
bLR = src.bLR;
btnSize = btnSize;
strPicture = src.strPicture;
return *this;
}
};
struct cbItemPaint
{
COLORREF clrBg;
CString picBg;
UINT nHeight;
LOGFONT logFontText;
COLORREF clrText;
UINT nFormatText;
cbItemPaint & operator = ( cbItemPaint & src)
{
clrBg = src.clrBg;
picBg = src.picBg;
nHeight = src.nHeight;
logFontText = src.logFontText;
clrText = src.clrText;
nFormatText = src.nFormatText;
return *this;
}
};
struct xui_cbItemContent
{
enum xField
{
CBIC_TEXT = 1 << 1,
CBIC_PIC = 1 << 2,
CBIC_DATA = 1 << 3,
};
UINT nMask;
CString strText;
CString strPicture;
int nItemData;
xui_cbItemContent & operator = ( xui_cbItemContent & src)
{
nMask = src.nMask;
strText = src.strText;
strPicture = src.strPicture;
nItemData = src.nItemData;
return *this;
}
};
UINT nMask;
cbEdit cbEditItem;
cbBtn cbBtnNormal, cbBtnSel;
cbItemPaint cbItemBgNormal, cbItemBgSel;
CList< xui_cbItemContent, xui_cbItemContent&> listItem;
xui_logComboBox & operator = ( xui_logComboBox & src)
{
nMask = src.nMask;
cbEditItem = src.cbEditItem;
cbBtnNormal = src.cbBtnNormal;
cbBtnSel = src.cbBtnSel;
cbItemBgNormal = src.cbItemBgNormal;
cbItemBgSel = src.cbItemBgSel;
POSITION posItem = NULL;
posItem = src.listItem.GetHeadPosition();
while( posItem)
{
listItem.AddTail( src.listItem.GetAt( posItem));
///
src.listItem.GetNext( posItem);
}
return * this;
}
};

...全文
100 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
stonewater 2010-08-11
  • 打赏
  • 举报
回复
默认拷贝构造函数一般是浅拷贝
stonewater 2010-08-11
  • 打赏
  • 举报
回复
ui_logComboBox xLogCb=CResKeeper::m_logComboBox
这样会调用拷贝构造函数(你没有定义,会有个默认拷贝构造函数,默认拷贝构造函数不能满足你某些成员变量的行为)
xui_logComboBox xLogCb;//会调用默认构造函数
xLogCb=CResKeeper::m_logComboBox; //调用你定义的操作符=函数
ruoge2007 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 stonewater 的回复:]

xui_logComboBox xLogCb=CResKeeper::m_logComboBox;//此处出现caerror C2440: 错误
改成
xui_logComboBox xLogCb;
xLogCb=CResKeeper::m_logComboBox;
或者定义一个拷贝构造函数,在其中进行类似于xui_logComboBox & operator = ( xui_l……
[/Quote]

xui_logComboBox xLogCb;
xLogCb=CResKeeper::m_logComboBox;
这样是可以的,这是咋回事呢?ui_logComboBox xLogCb=CResKeeper::m_logComboBox,行为 与
xui_logComboBox xLogCb;
xLogCb=CResKeeper::m_logComboBox; 行为区别在哪里呢。
stonewater 2010-08-11
  • 打赏
  • 举报
回复
xui_logComboBox xLogCb=CResKeeper::m_logComboBox;//此处出现caerror C2440: 错误
改成
xui_logComboBox xLogCb;
xLogCb=CResKeeper::m_logComboBox;
或者定义一个拷贝构造函数,在其中进行类似于xui_logComboBox & operator = ( xui_logComboBox & src)这个函数的处理
senlinzhiwang 2010-08-11
  • 打赏
  • 举报
回复
如果不是的话,去检查一下。
xui_logComboBox xLogCbA, xLogCbB;
xLogCbA = xLogCbB;//此处无此错误

这个是两个相同类型的变量,当然没问题了。
senlinzhiwang 2010-08-11
  • 打赏
  • 举报
回复
m_logComboBox是一个这个类型xui_logComboBox的对象吗?

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧