求助:一句使用友元函数的语句编译通不过。
(下面程序经楼下大虾指点后已进行了修改,OK,谢谢)这是来源于自考教材上的程序,有friend 关键词的语句在visual studio 2010中
编译通不过,如何改,请大虾指点,谢谢!
#include "stdio.h"
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
#include <iostream>
using namespace std;
class complex{
private:
int real;
int image;
public:
complex(int r=0,int i =0){ real=r;image=i;};
friend complex operator + (complex&,complex&);
void show(){ cout<<real <<"+"<<image <<"i;};
};
complex operator +(complex&a,complex&b){
int r=a.real +b.real;
int i=a.image +b.image;
return complex(r,i);
}
void main(){
complex x(6,8),y(9,6),z;
z=x+y;
x.show();
cout<<"+ ";
y.show();
cout<<" = ";
z.show();
cout<<endl;
}
[ 本帖最后由 bardon 于 2011-2-17 23:21 编辑 ]