新微赢技术网

标题: 拷贝构造函数的问题 [打印本页]

作者: 天地之一    时间: 2009-11-4 01:42
标题: 拷贝构造函数的问题
#include "iostream.h"
class  CComplex
{
private:
    double real;
    double imag;
public:
    CComplex();
    CComplex(double r, double i);
    CComplex(CComplex &c);       //复数类的拷贝构造函数声明
    void Set(double r, double i);
    void Print();
    CComplex Add(CComplex c);
    CComplex Sub(CComplex c);
};
CComplex::CComplex()
{
    real = 0.0;
    imag = 0.0;
}
CComplex::CComplex (double  r, double i)
{
    real = r;
    imag = i;
}
CComplex::CComplex (CComplex &c)     //复数类的拷贝构造函数定义
{
    real = c.real;
    imag = c.imag;
}
void CComplex::Set(double r, double i)
{
    real = r;
    imag = i;
}
void CComplex::Print()
{
    cout << "(" << real << "," << imag << ")" << endl;
}
CComplex CComplex::Add(CComplex c)
{
    CComplex temp;
    temp.real = real + c.real;
    temp.imag = imag + c.imag;




欢迎光临 新微赢技术网 (http://bbs.weiying.cn/) Powered by Discuz! X3.2