1
I created a class, which has 4 attributes int valInt
, float valFloat
, double valDouble
, bool valBool
, and a method called getValue()
of the auto type that returns the value according to another attribute called type, follows the code:
auto
ShareMemory::
getValue()
{
switch (type) {
case 0:
return valInt;
break;
case 1:
return valFloat;
break;
case 2:
return valDouble;
break;
case 3:
return valBool;
break;
}
}
When compiling, it accuses the following error in the line of return valFloat
:
error: 'auto' in Return type deduced as 'float' here but deduced as 'int' in earlier Return statement.*
Is there any other way for me to return any of these values, without it pulling the type of the first Return?
Thank you for your reply, you opened up a range of options, and a lot of things I didn’t know, I’ll study them, thank you.
– Morvy