型式種類 1.

complex complex::operator+(const complex & A)const
{
    complex b;
    b.real = real + A.real;
    b.imag = imag + A.imag;
    return b; //b物件設定給c3
}

型式種類  2.

complex complex::operator+(const complex & A)const
{
     real + A.real;
     imag + A.imag;
    return complex(real + A.real,imag + A.imag); //設定值設定給物件
}

int main()
{
    complex c1(4.3, 5.8);
    complex c2(2.4, 3.7);
    complex c3;
    c3 = c1 + c2;

arrow
arrow
    全站熱搜

    minsin 發表在 痞客邦 留言(0) 人氣()