using user input as a var.
Hey i was wondering if there was anyway to take a 'string' and use it in place of an int/char or whatever.
ie
Code:
cout<<"Type in what kind of shape you would like.\n";
cin>>Shape_Name;
Draw(Shape_Name);
Im not sure if that makes sense...but lets say ive got a large program with many 'shape instances' and I dont want to make a huge 'switch/case'. So instead of 'switch/case' I just take user input and somehow change it into a 'variable' and pass it into a function.
*shrugs*maybe that is a foolish request, but if that were possible...man that would open up a whole new world to me =/
Nope. not possible in C/C++
I think you are trying to emulate what many BASH shell scripers do:
Code:
#!/bin/bash
read input_name
read input_value
$input_name="$input_value"
export $input_name
would allow you to change your TERM settings by:
running it,
typing "TERM" <enter>, and
typing "screen" <enter>.
There is no way to do such things in C/C++, because of the ways that C/C++ processes it and AS IT COMPILES IT. BASH and PERL (i think you can do it in PERL too) are (mostly) interpreted, which makes it easier to do this. The only way that I could see doing this would be something along the lines of using user unput as one of the fields of a template class:
Code:
...
char input[1024];
cin >> input;
newTemplate = template<graphic, input>;
...
void polymorph(template<graphic, "SQUARE">) { ... }
void polymorph(template<graphic, "CIRCLE">) { ... }
...
but i'm wntirely lost when it comes to templates, this may not even be possible.