Here it is: I want to create a void function that receives two known types of values, and the other - anything. The code will look like this:
void change_settings(string element, short setting, ??? value) { switch (setting) { case ST_NAME: // Cast value to string or char* and change element.name break; case ST_AMOUNT: // Cast value to integer and change element.amount break; case ST_ENABLED: // Cast value to boolean and change element.enabled break; } }
I tried to create a value type of const void* , but I get an error ( cast from 'const void*' to 'short int' loses precision ) because I just did this: short name = (short)value , which should be crazy desperate test, hoping that he was lucky. Now I donβt know if there is a way to do this, pass the pointer to any variable, and then convert it to what it is (I know what type of variable to expect depending on each case. How do I do this? Thanks!
c ++ function types arguments void
ali
source share