hi,
I was wondering if/is there a way to turn/use 2 char/string variables, join them, and then use the (joined) variable to call a function ?
For example;
Code:
char *varA, *varB; //char variables taken from a table based on user input.
char *varAB;
//where varAB == varA+varB & subsequently calls different varAB functions
void varAB1(double)
{
//do function;
}
void varAB2(double)
{
//do function;
}
I've tried using this (& hopefully shows more clearly what I'm 'trying' to do);
Code:
#define fPrint1(VAR,double) f ## VAR ## PRINT2(double)
#include <iostream>
void fONEPRINT2(double &);
void fTWOPRINT2(double &);
int main()
{
char *table[] = {"ONE", "TWO", "THREE", "FOUR"};
char *TABLE = table[1];
double i=100;
fPrint1(TABLE,i);
std::cin.get();
}
void fONEPRINT2(double &i)
{
std::cout<<"fONEPrint\n";
std::cout<<i;
}
void fTWOPRINT2(double &i)
{
std::cout<<"fTWOPrint\n";
std::cout<<i;
}
But fPrint1(TABLE,i) always seems to take on the literal meaning TABLE, when I want it to take on its meaning in the *table[] & use that string in order to call the function.
Just wondering if such a thing is possible, & if so how, or do the functions need to be called by their literal names.
Any tips/pointers etc appreciated, thanks.
p.s. still learning.