1.问题来源(VC++ 6.0):
struct STone
{
int x;
};
struct STtwo : public STone
{
int y;
};
void CCccDlg::OnOK()
{
// TODO: Add extra validation here
STone o1; o1.x = 9;
STtwo o2 = o1;
CDialog::OnOK();
}
Output:
E:\Test\ccc\cccDlg.cpp(187) : error C2440: 'initializing' : cannot convert from 'struct STone' to 'struct STtwo'
No constructor could take the source type, or constructor overload resolution was ambiguous
Generating Code...
Error executing cl.exe.
ccc.exe - 1 error(s), 0 warning(s)
2.原因:
???
3.解决方法:
在子类STtwo中增加如下的成员函数:
STtwo( STone oOne )
{
STone::operator = ( oOne );
}
*若是使用STtwo o2; o2 = o1; 则需在STtwo中增加如下成员函数:
STtwo& operator = ( STone oOne)
{
STone::operator = ( oOne );
}
阅读(1665) | 评论(0) | 转发(0) |