| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 485 人关注过本帖
标题:运算符重载问题
只看楼主 加入收藏
jxk821015
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-8-22
收藏
 问题点数:0 回复次数:3 
运算符重载问题

下面程序在vc6.0里面运行报错!请指教!报错在后面有提示!
**********************************
#include <iostream>
using namespace std;
class Test
{
public:
Test(int a = 0)
{
Test::a = a;
}
friend Test operator +(Test,Test);
friend Test operator ++(Test);
public:
int a;
};
Test operator +(Test temp1,Test temp2)//+运算符重载函数
{
//cout<<temp1.a<<"|"<<temp2.a<<endl;//在这里可以观察传递过来的引用对象的成员分量
Test result(temp1.a+temp2.a);
return result;
}
Test operator ++(Test temp)//++运算符重载函数
{
temp.a++;
return temp;
}
int main()
{
Test a(100);
Test c=a+a;
cout<<c.a<<endl;
c++;
cout<<c.a<<endl;

}
***********************************************
--------------------Configuration: ddd - Win32 Debug--------------------
Compiling...
Text2.cpp
D:\source\ddd\Text2.cpp(10) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.

Text2.obj - 1 error(s), 0 warning(s)

搜索更多相关主题的帖子: 运算符 重载 
2006-09-15 15:30
corrupt
Rank: 2
等 级:新手上路
威 望:3
帖 子:535
专家分:0
注 册:2004-9-29
收藏
得分:0 
#include <iostream>
using namespace std;
改为
#include <iostream.h>试试

2006-09-15 17:10
makewelldone
Rank: 1
来 自:江苏南京
等 级:新手上路
帖 子:97
专家分:0
注 册:2006-9-25
收藏
得分:0 
有时编译器就是这样的.你不防在友元涵数的返回值加上一个&,我想它的返回值是用的引用.
friend Test& operator +(Test,Test);
friend Test& operator ++(Test);
2006-10-10 07:50
天使坠落的眼泪
Rank: 2
等 级:新手上路
威 望:5
帖 子:204
专家分:0
注 册:2006-5-16
收藏
得分:0 

这粘贴板出问题了,粘贴不上去,你去这里看

[URL=http://post.baidu.com/f?kz=139489333]http://post.baidu.com/f?kz=139489333[/URL]

樹欲靜而風不止... http://blog./seablue_xj
2006-10-11 09:16
快速回复:运算符重载问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012269 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved