如何重载条件运算符? [英] How to overload the conditional operator?
问题描述
可能的重复:
操作员重载
我不知道如何在cpp中重载条件运算符?
int a,b,c;
a = 10;
b = 11;
c =(a> b)? a:b;
是否有可能?
几个操作符不能重载。这些运算符将名称而不是对象作为其右操作数:
-
直接成员访问
-
范围解析(::)
此外,新的typecast操作符:static_cast<>,dynamic_cast<>,reinterpret_cast< ,and const_cast<>,并且#和##预处理器令牌不能重载。
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=23
Possible Duplicate:
Operator overloading
I was wonder how can I over load the Conditional operator in cpp?
int a,b,c;
a=10;
b=11;
c = (a>b) ? a : b;
Is it possible?
Several operators cannot be overloaded. These operators take a name, rather than an object, as their right operand:
Direct member access (.)
Deference pointer to class member (.*)
Scope resolution (::)
Size of (sizeof)
The conditional operator (?:) also cannot be overloaded.
Additionally, the new typecast operators: static_cast<>, dynamic_cast<>, reinterpret_cast<>, and const_cast<>, and the # and ## preprocessor tokens cannot be overloaded.
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=23
这篇关于如何重载条件运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!