运算符重载问题。

ra3 2002-05-10 08:35:34
运算符重载具体该怎么做?可不可以举一个简单一些的例子。这个问题太难了。

//...
...全文
22 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgdqlc 2002-05-10
  • 打赏
  • 举报
回复
函数重载明白吗?运算符重载其实是一样的道理。你应该这样理解。
eion 2002-05-10
  • 打赏
  • 举报
回复
看看这里,有一篇文章,你可用,我回答的
题目:“请问怎么重载<运算符”
URL:
http://www.csdn.net/expert/topic/708/708369.xml?temp=.166073
ra3 2002-05-10
  • 打赏
  • 举报
回复
我明白了,谢谢!
prototype 2002-05-10
  • 打赏
  • 举报
回复
a more complete example to show what it can do:

class A{
int i;
public:
A& operator[] ( int a ) { i = a; return *this; }
void f() { cout << i; }
};

A b;

a[1].f(); // output '1'.


i am sure you can think of better use of the operator[].
ra3 2002-05-10
  • 打赏
  • 举报
回复
class A{
A& operator [] ( int a ) { ... }
};

把它这样定义,可以做什么呢?
prototype 2002-05-10
  • 打赏
  • 举报
回复
it is actually the same as you overload the normal functions. only need to pay attention to the requirement for the arguments for each particular operator.

for example. only 1 arugment is allowed for 'operator []'. in your class, you can define it as:

class A{
A& operator [] ( int a ) { ... }
};

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧