How can one create an operator to be used in their own program? For example, say I want the character '@' to be used for multiplying numbers together. How do the standard C++ operators work?
How can one create an operator to be used in their own program? For example, say I want the character '@' to be used for multiplying numbers together. How do the standard C++ operators work?
You can't. Plain and simple.Originally Posted by SentralThey're little tokens that the compiler understands and can convert accordingly when it sees them.Originally Posted by Sentral
Sent from my iPadŽ
But you could maniuplate some operators to do something ... like you could overload the + operator in a class you made to subtract or something. Not the best of ideas though. It leads to confusion
Well... you can create a @ operator and use it to perform multiplication, or addition, or whatever.
You need to create a parser and a small lexer that will encapsulate the rules.
it could be as simple as:
Code:double calculate(int left_arg, int right_arg, char oper) { switch(oper) { case '@': return left_arg * right_arg; break; case /* ... */ /* ... */ } }
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
I believe he's referring to an operator to be used in the code's syntax, not inside of a program.Originally Posted by Mario F.
However, you can in fact use a nonstandard operator to be used in your C++ code! All you have to do is write your own C++ compiler that doesn't completely conform to the standards. Enjoy!
Sent from my iPadŽ
He doesn't need a compiler for that either. Just a parser that translates his altered code to something C++ standard compiler can read.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
Actually, the code that Mario F. posted might work! I don't want to change the C++ language, I just want some operators to make things easier for my specific program. I perhaps should've made that clearer? Anyway, I could just stick operators in a header file, and use the symbol rather than a call to a function, which is what I wanted. DANKE!
Actually your first sentence was clear enough, but theCould be argued as being the exact opposite of clear. Some kind of... I don't know... non-anti-clearite... I don't know, I don't think there is a word for it. But that's what it is!How do the standard C++ operators work?
Sent from my iPadŽ