c++为什么编译不过去

[复制链接]
查看11 | 回复3 | 2011-3-31 21:59:52 | 显示全部楼层 |阅读模式
#include
using namespace std;
class multiply
{
private:
int n;
int m;
public:
multiply(int in=0,int im=0)
{
n=in;
m=im;
}
multiply(multiply &mu)
{
n=mu.n;
m=mu.m;
}
void Print()
{
cout<<n<<"x"<<"^"<<m<<"\n";
}
friend multiply operator*(const multiply &,const multiply &);

friend multiply operator+(const multiply &,const multiply &);//为什么这行编译不过去 说内部编译错误
};
multiply operator*(const multiply & c1,const multiply & c2)
{
return multiply(c1.n*c2.n,c1.m+c2.m);
}
multiply operator+(const multiply & c1,const multiply & c2);
{
return multiply(c1.n+c2.n,c1.m);
}
int main()
{
multiply c1(2,3),c2(3,1),c;
c1.Print();
c2.Print();
c=c1*c2;
c.Print();
return 0;
}

回复

使用道具 举报

千问 | 2011-3-31 21:59:52 | 显示全部楼层
下边这个操作符重载后边多了一个分号,去掉就可以编译通过了。multiply operator+(const multiply & c1,const multiply & c2);//就是这里,去掉分号即可。{ return multiply(c1.n+c2.n,c1.m);}我在VS2005上已经编译通过了。
回复

使用道具 举报

千问 | 2011-3-31 21:59:52 | 显示全部楼层
把#include改为#include把multiply operator+(const multiply & c1,const multiply & c2);{ return multiply(c1.n+c2.n,c1.m);}函数定义头部后面的分号去掉
回复

使用道具 举报

千问 | 2011-3-31 21:59:52 | 显示全部楼层
multiply operator+(const multiply & c1,const multiply & c2);//就是这里,去掉分号即可。{ return multiply(c1.n+c2.n,c1.m);}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行