How about you:
1. determine the type in the string in the function
2. return an arbitrary integer into main from that function: ie. int = 1, float = 2, double = 3, etc..
3. then, switch the return variable and do the correct conversion according to what type it is.
This isn't very efficient and advisable I bet (I am a beginner too). Alternatively you could create a struct containing a variable for each type:
1 2 3 4 5
|
struct types {
int int_num;
float float_num;
//etc..
};
|
You first initialize an object of this struct by setting all variables to zero. Then you pass this struct by reference to the function that determines the type in the string and does the conversion. If the string represents an int, you set the int_num variable in the struct to the result of the string conversion to int. Likewise you determine the type in the string, do the conversion and go save the result into the correct variable of the object.
1 2 3 4 5 6
|
void function_converting_string(types &types_object, string str){
//determine what type contained in string
//do conversion
// save result in correct variable in the types_object
//example - if result is int do: types_object.int_num = str_to_int_conversion_result;
}
|
Please do correct me if any of these suggestions are completely wrong. I am sure they aren't really efficient, but as I said, I'm still a beginner! :)
Beavey