hello all, whats up? i have a question about casting and overloading operators.
can i invent in my code new operator like =-%^ for example, or use only the existed (to rewrite them).
thank you a lot
shahar:rolleyes:
2 replies to this topic
#1
Posted 25 August 2011 - 07:52 AM
|
|
|
#2
Posted 26 August 2011 - 05:22 AM
You cannot invent your own operators, as operators are integral to the language's grammar. You would have to write your own adaptation of the language and build a compiler in order to invent new operators.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid
#3
Posted 26 August 2011 - 10:32 PM
You can only overload the existing operators (or it wouldn't be overloading them, now would it :)). But, just because you can doesn't mean you should. When overloading operators make sure that the overload makes sense without complex explanations. For example the String class overloads the + operator to perform concatenation. This makes 'sense'. But it doesn't overload the - operator as what would it mean? Remove those characters? Remove that word? Remove it if it's found on the end? etc.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









