64,639
社区成员
发帖
与我相关
我的任务
分享
class myfunc10derive2
{
public:
myfunc10derive2(int id2) : m_id2(id2) {};
const myfunc10derive2 operator + (const myfunc10derive2& rhs) const
{
myfunc10derive2 md2(rhs);
md2.m_id2 += m_id2;
return md2;
}
const myfunc10derive2& operator ++ ()const
{
m_id2++;
return const_cast<const myfunc10derive2&>(*this);
}
public:
mutable int m_id2;
};
void func10()
{
const myfunc10derive2 md2_5(25);
md2_5.m_id2 = 99;
md2_5.operator ++(); // ---> 这句出错
myfunc10derive2 md2_6(26);
md2_6.operator ++();
md2_6.operator ++().operator ++(); // ---> 这句出错
}
自己对比吧const myfunc10derive2 md2_5(25);
class myfunc10derive2
{
public:
myfunc10derive2(int id2) : m_id2(id2) {};
const myfunc10derive2 operator + (const myfunc10derive2& rhs) const
{
myfunc10derive2 md2(rhs);
md2.m_id2 += m_id2;
return md2;
}
const myfunc10derive2& operator ++ ()
{
m_id2++;
return const_cast<const myfunc10derive2&>(*this);
}
public:
int m_id2;
};
void func10()
{
const myfunc10derive2 md2_5(25);
md2_5.m_id3 = 99;
md2_5.operator ++(); // ---> 这句出错
myfunc10derive2 md2_6(26);
md2_6.operator ++();
md2_6.operator ++().operator ++(); // ---> 这句出错
}