How to overload a conditional statement?

Possible duplicate:
Operator Overload

I was wondering how can I overload the Conditional statement in cpp?

int a,b,c; a=10; b=11; c = (a>b) ? a : b; 

Is it possible?

+2
source share
3 answers

Some operators cannot be overloaded. These operators take a name, not an object, as their right operand:

  • Direct Member Access (.)

  • Class member relationship indicator (. *)

  • Area Resolution (: :)

  • Size (sizeof)

The conditional operator (? :) also cannot be overloaded.

In addition, new type operators: static_cast <>, dynamic_cast <>, reinterpret_cast <>, and const_cast <>, and preprocessor tokens # and ## cannot be overloaded.

http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=23

+5
source

You cannot overload a conditional statement.

+5
source

No, you cannot overload a conditional statement, as it simply shortens the simple if..else block.

However, you can overload operators used in state, but not for primitive types such as int , as you have in the above example.

+1
source

All Articles