简单的关于运算符重载的程序 求高手解答
#include "stdafx.h"\\将运算符重载为类的成员函数#include <iostream>
using namespace std;
class Complex
{
private:
double r;
double i;
public:
Complex(double x=0.0,double y=0.0)
{
r=x;
i=y;
}
Complex operator+(Complex &c);
{
Complex t;
t.r=r+c.r;
t.i=i+c.i;
return t;
}
void show()
{
cout<<"("<<r<<","<<i<<")";
}
};
int main()
{
Complex a(10,20.0),b(30.0,40.0),c;
c=a+b;
a.show;
cout<<'+';
b.show;
cout<<'=';
c.show();
cout<<endl;
return 0;
}
调试结果为
1>f:\visual studio 2012\consoleapplication32\consoleapplication32\consoleapplication32.cpp(20): error C2059: 语法错误:“{”
1>f:\visual studio 2012\consoleapplication32\consoleapplication32\consoleapplication32.cpp(20): error C2334: “{”的前面有意外标记;跳过明显的函数体
1>f:\visual studio 2012\consoleapplication32\consoleapplication32\consoleapplication32.cpp(37): error C3867: “Complex::show”: 函数调用缺少参数列表;请使用“&Complex::show”创建指向成员的指针
1>f:\visual studio 2012\consoleapplication32\consoleapplication32\consoleapplication32.cpp(39): error C3867: “Complex::show”: 函数调用缺少参数列表;请使用“&Complex::show”创建指向成员的指针
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========