I need to find some way to mock an overload of a function return type in C++.
I know that there isn\'t a way to do that directly, but I\'m hoping there\'s some out-o
The answer is simple just declare the function returning void* type and in the definition return a reference to the variable of different types. For instance in the header (.h) declare
void* RetrieveValue(string dataString1);
And in the definition (.cpp) just write
void* RetrieveValue(string dataString1)
{
if(dataString1.size()>4)
{
double value1=(double)dataString1.size();
return &value1;
}
else
{
string value2=dataString1+"some string";
return &value2;
}
}