How do I detect/identify inside the function, the data type of the argument passed in, especially when it's a pointer to pointer (as in float ** my_matrix)? Once the function knows the data type, it can manage the printing accordingly.
Just create 2 functions one that accepts a pointer to a pointer of a float as a parameter and one that accepts a string. The compiler will then figure out which one to use by what you pass in as a argument to the function.
For example (I left out the pointer to a pointer stuff so you can figure it out).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void print(const std::string& myString)
std::cout << myString << std::endl;
void print(float myFloat)
std::cout << myFloat << std::endl;
print("Hello"); // Will call the string version
print(1.05); // Will call the float version
Leaving aside all of the above, is there way in C++ to detect the data type of an variable (forget functions and overloading), especially a pointer-to-pointer? For instance I could detect an integer or float data type by checking if the variable value is unchanged in upper & lower case (a string containing alpha numeric characters would fail that test).
How do I check if a variable is of type ** (pointer-to-pointer)?