一个小问题,简单
#include "stdio.h"
class CBase
{
public:
CBase(){m_iValue=0;}
CBase& operator =(int v)
{
m_iValue=v;
return *this;
}
int Get_iValue()const
{ return m_iValue;}
void Set_iValue(int v)
{ m_iValue=v; }
private:
int m_iValue;
};
class CSon :public CBase
{
public:
CSon(){m_fValue=0.0;}
CSon& operator =(const CSon& son)
{
CBase::operator=(son);//??????????????????????????????????
m_fValue=son.m_fValue;
return *this;
}
float Get_fValue()const
{ return m_fValue;}
void Set_fValue(float v)
{
m_fValue=v;
}
private:
float m_fValue;
};
int main(int argc, char* argv[])
{
CSon son1,son2;
//son2=34;
//son2.operator =(34);
son2.CBase::operator =(34);
son2.Set_fValue((float)21.33);
son1=son2;
printf("%8.2f %d\n",son1.Get_fValue(),son1.Get_iValue());
return 0;
}
请问上面的程序打问号的地方,CBase重载=好不是要求参数是int型码?为什么可以是CSon类型呢,多谢!
程序经过我编译可以运行