运算符号重载注意点
2008-01-29 15:44
323 查看
//二元运算符的参数之一必须是包含类型
//参数有一个必须是所在类
//-======================================================
using System;
using System.Collections.Generic;
using System.Text;
namespace MyStudy
...{
class Program
...{
static void Main(string[] args)
...{
result r1 = new result(10, 20);
test r2 = new test();
result r = r1 + r2;
Console.WriteLine(r.i);
}
}
public class result
...{
public static result operator +(result c1, test c2) //参数有一个必须是所在类
...{
result t1 = new result(0, 0);
t1.i = c1.i + c2.i;
t1.j = c1.j + c2.j;
return t1;
}
public int i,j;
public result(int i,int j)
...{
this.i = i;
this.j = j;
}
}
public class test
...{
public int i=100, j=200;
}
}
此外
1,在对比较运算符号进行重载时,要求成对重载(==, !=)(>,<)(>=,<=)
2.比较运算符必须返回bool类型的值.
相关文章推荐
- 运算符号重载:前置与后置单目运算++
- 【C++】重载运算符号时的函数返回值类型问题
- loner_li 机试题 编写一个简单的计算器实现加减乘除:输入两个数字和一个运算符号,输出结果(注意容错性)
- C++重载string类的+=运算符号
- 对运算符号进行重载,进行复数运算
- (转)运算符号重载
- C++运算符号重载
- 运算符号重载之自己转化为其它
- 逻辑运算符号
- error C2377: “resolver”: 重定义;typedef 不能由任何其他符号重载
- C++编程趣题1 在1~9中间填符号使运算结果等于100
- A + B Again 2057 有符号的64进位的运算
- mysql 中 = 符号判断的时候要注意等号左右的类型
- 第十四章——<<输入重载(注意处理错误)
- 符号重载
- c语言运算符号
- Java的运算符号(逻辑与、或、非、移位运算)
- OGNL表达式符号_注意
- C++运算符重载需要注意的地方