这道程序是不是有错啊?
这是一道C++书上的练习,我检查了一下,好像没有错,但就是不对,请高手们看下!#include<iostream>
using namespace std;
template<typename T>
class Complex
{public:
Complex(T r=0,T i=0);
void print()const;
friend Complex operator+(const Complex<T> &c1,const Complex<T> &c2);
private:
T Real,Image;
};
template<typename T>
Complex<T>::Complex(T r,T i)
{Real=r; Image=i;}
template<typename T>
Complex<T> operator+(const Complex<T> &c1,const Complex<T> &c2)
{T r=c1.Real+c2.Real;
T i=c1.Image+c2.Image;
return Complex<T>(r,i);
}
template<typename T>
void Complex<T>::print()const
{cout<<'('<<Real<<","<<Image<<')'<<endl;
}
void main()
{Complex<double> c1(2.5,3.7),c2(4.2,6.5);
Complex<double> c;
c=c1+c2;
c.print();
}