匹配“"运算符是“ [英] Matching '' operator is required for '

查看:80
本文介绍了匹配“"运算符是“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码段重载<运算符

I am using the following code snippets for overloading < operator

Class example
{

static bool operator < (example a ,example b)
{
 /* code goes here*/
}
}


当我尝试编译它时,我收到一条错误消息,说
运算符<需要匹配的运算符>也要定义.

如何克服此错误


when i try to compile it,I get a error saying that
the operator < requires a matching operator > also to be defined.

How to over come this error

推荐答案

这意味着,如果声明小于"运算符,则还必须声明大于"运算符.至少添加此内容:
What it means is that if you declare a "less than" operator, you must also declare a "greater than" operator. Add this at a minimum:
static bool operator > (example a ,example b)
{
 return !(b < a);
}


了解以下网址,以了解原因:
http://www.vijaymukhi.com/documents/books/csbasics/chap12.htm [ ^ ]
http://msdn.microsoft.com/en-us/library/edbzxf5f%28v = vs.90%29.aspx [ ^ ]
have a look at the following url for knowing the reason :
http://www.vijaymukhi.com/documents/books/csbasics/chap12.htm[^]
http://msdn.microsoft.com/en-us/library/edbzxf5f%28v=vs.90%29.aspx[^]


这篇关于匹配“"运算符是“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆