类型转换操作符operator
1.无返回类型
2.无参数
3.有return语句
1.类类型转换为基本类型
class CA
{
public:
CA(int nNum):m_nA(nNum){}
operator int()
{
return m_nA;
}
private:
int m_nA;
};
2.不同类之间类成员转换
class CB
{
public:
CB(int nNum):m_nB(nNum){}
operator CA()
{
CA obj;
return obj;
}
private:
int m_nB;
};