在类内添加:
COMPLEX( ){ }
COMPLEX(DOUBLE A,DOUBLE B)
{
REAL =A;
IMAGE=B;
}
类外添加:
COMPLEX ADD(COMPLEX C1,COMPLEX C2)//定义友元函数
{
COMPLEX C3;
C3.REAL=C1.REAL+C2.REAL;//访问COMPLEX类中的私有成员
C3.IMAGE=C1.IMAGE+C2.IMAGE;
RETURN C3;
}
在类内添加:
COMPLEX( ){ }
COMPLEX(DOUBLE A,DOUBLE B)
{
REAL =A;
IMAGE=B;
}
类外添加:
COMPLEX ADD(COMPLEX C1,COMPLEX C2)//定义友元函数
{
COMPLEX C3;
C3.REAL=C1.REAL+C2.REAL;//访问COMPLEX类中的私有成员
C3.IMAGE=C1.IMAGE+C2.IMAGE;
RETURN C3;
}