operator in C++

why we can not overload these operators..?

1-> ::
2-> .
3-> .*
4->?:

is there any reason behind this?

Last edited on
This is because, it may cause serious problems or syntactically not correct.
The compiler evaluates these operators--they are not evaluated at runtime--and therefore cannot be replaced with your own runtime code.

Also, scope resolution and member access operators(::,->) work on names not values, and one cannot create a code that works on names because, C++ has to syntax for writing code that work on names.

Hope it HELPS!!!
Last edited on
To quote Bjarne Stroustrup:

There is no fundamental reason to disallow overloading of ?:. I just didn't see the need to introduce the special case of overloading a ternary operator. Note that a function overloading expr1?expr2:expr3 would not be able to guarantee that only one of expr2 and expr3 was executed.


...

Operator . (dot) could in principle be overloaded using the same technique as used for ->. However, doing so can lead to questions about whether an operation is meant for the object overloading . or an object referred to by . ... This problem can be solved in several ways. At the time of standardization, it was not obvious which way would be best
There is no fundamental reason to disallow overloading of ?:.

you mean allow?
Last edited on

@Aceix thanx for reply...
I just have 2 Q to ask ?
1 Q-> scope resolution operator :: and member acces operator -> work on names not on values please elaborate this?

2 Q->diff b/t work on names and work on values?


Working on names mean they work with the names of functions and members of a data structure, and not their values, while working on values mean, they deal with the values variable or constants or other data types contain. eg the assignment operator(=).
Last edited on
Topic archived. No new replies allowed.