| | |
variables holding operators?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
you can use it in a switch statement
C++ Syntax (Toggle Plain Text)
int b = 1; int c = 2; int d = 0; switch(a) { case '+': d = b * c; break; case '-': d = b - c; break; case '/': d = b / c; break; // etc }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
•
•
OK I am wondering Can you make a variable hold an operator.
Such as say +, -, / etc...
And if so can that variable be used to replace an operator in an equation?
for instance
char a = "+";
int b = (2 a 3);
thoguh that doesn't work itself i think it conveys what i am looking for.
c Syntax (Toggle Plain Text)
#define a + int b = (2 a 3);
But 'a' is not really a variable here.
And I see no reason why you would want to do that...
•
•
•
•
You can do this to have the same effect:
c Syntax (Toggle Plain Text)
#define a + int b = (2 a 3);
But 'a' is not really a variable here.
And I see no reason why you would want to do that...
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2007
Posts: 8
Reputation:
Solved Threads: 1
•
•
•
•
You might want to do something like that when writing a calculator. for example, if you enter "2 * 3" then your program needs to figure out what to do.
Are there any compliers with additions that will fix some things, simple things like length_of(Array), treat_as_value(char). So many things that would make the programing both easier and less taxxing on memory and processor time. And if it was compiled to exe it should retain portability or am i missing something?
I don't know if not is there a langauge I should try that doesn't have such drastic oversights?
•
•
•
•
Are there any compliers with additions that will fix some things, simple things like length_of(Array), treat_as_value(char).
•
•
•
•
So many things that would make the programing both easier and less taxxing on memory and processor time. And if it was compiled to exe it should retain portability or am i missing something?
If you want to get reall deep into parsing equations then try YACC (Yet Another Compiler Compiler)
Last edited by Ancient Dragon; Mar 18th, 2007 at 3:38 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Where to get started with Web Programming (IT Professionals' Lounge)
- Zend PHP Certification (PHP)
- Objects (C)
Other Threads in the C++ Forum
- Previous Thread: Linked Lists Help C++
- Next Thread: Dynamic Allocation
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






