以下是我将类模板和重载结合起来的代码,可是会报错。张玉老师让问老贺。
/*
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作 者: 沈远宏
* 完成日期:2013 年 04月15日
* 版 本 号:v1.0
* 问题描述:一个定义完整的类,是可以当作独立的产品发布,成为众多项目中的“基础工程”,这样的类在方案二的基础上,
扩展+、-、*、/运算符的功能,使之能与double型数据进行运算。设Complex c; double d;c+d和d+c的结果
为“将d视为实部为d的复数同c相加”,其他-、*、/运算符类似。
* 输出:两个复数+,-,*,/后的结果输出
*/
#include <iostream>
using namespace std;
template <class numtype>
class Complex
{
public:
Complex(numtype r,numtype i)
{
real=r;
imag=i;
}
Complex<numtype> operator+(numtype &d);
Complex<numtype> operator+(numtype &d,Complex <numtype>&c);
Complex<numtype> operator-(Complex <numtype>&c, numtype&d);
Complex<numtype> operator-(numtype &d,Complex<numtype> &c);
Complex<numtype> operator*(Complex<numtype> &c, numtype &d);
Complex<numtype> operator*(numtype &d,Complex<numtype> &c);
Complex<numtype> operator/(Complex<numtype> &c, numtype &d);
Complex<numtype> operator/(numtype &d,Complex<numtype> &a