| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1096 人关注过本帖
标题:[求助]c++ji基础问题
只看楼主 加入收藏
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
 问题点数:0 回复次数:3 
[求助]c++ji基础问题

这是我写的重载运算符的小程序但是有错误,希望大家帮忙看一下。谢谢!
#include<iostream>
using namespace std;
class Point {
private:int m;
public: Point(int a){m=a;}
Point operator ++(int){ Point point=*this;
++( *this);
return point;}
Point operator --(int){Point point=*this;
--(*this);
return point;}
};
void main(){
int m;
cout<<"please enter your numbaer:"<<endl;
cin>>m;
Point point(m);
cout<<"point++"<<point++<<endl<<"point--:"<<point--<<endl;
}
错误调试:
--------------------Configuration: 11 - Win32 Debug--------------------
Compiling...
11.cpp
D:\学习文件\CL\8-10\11\11.cpp(7) : error C2675: unary '++' : 'class Point' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\学习文件\CL\8-10\11\11.cpp(10) : error C2675: unary '--' : 'class Point' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\学习文件\CL\8-10\11\11.cpp(18) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Point' (or there is no acceptable conversion)
执行 cl.exe 时出错.

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

搜索更多相关主题的帖子: Point point 基础 operator 
2006-10-24 08:25
sunnvya
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:1094
专家分:0
注 册:2005-11-23
收藏
得分:0 

Point operator ++(int){
++(this.m);
return this;}
Point operator --(int){
--(this.m);
return this;}
再重载“<<";


http://www. 第二站>>>提供源码下载
2006-10-24 11:08
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
得分:0 

能写详细点吗 ?我对运算符重载不太会,希望你能帮我一下!谢谢版主啦!麻烦你了!

2006-10-24 19:50
song4
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:38
帖 子:1533
专家分:4
注 册:2006-3-25
收藏
得分:0 
cout<<"point++"<<point++<<endl<<"point--:"<<point--<<endl;
}
这里没有<<运算符
另外Point operator ++(int){ Point point=*this;
++( *this);这是什么??你不是正在做这个么???
2楼对了

嵌入式 ARM 单片机 驱动 RT操作系统 J2ME LINUX  Symbian C C++ 数据结构 JAVA Oracle 设计模式 软件工程 JSP
2006-10-25 21:58
快速回复:[求助]c++ji基础问题
数据加载中...
 
   



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

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