I need to find a way to recompose overloading the return type of a function in C ++.
I know that there is no direct way to do this, but I hope that there will be some simple way. We are creating an API for users to work with and they will pass a data string that retrieves a value based on the string information. These values ββare different types. Essentially, we would like to let them:
int = RetrieveValue(dataString1); double = RetrieveValue(dataString2);
But this does not work in C ++ (obviously). Right now, we are setting it up so that they call:
int = RetrieveValueInt(dataString1); double = RetrieveValueDouble(dataString2);
However, we do not want them to know what type of data row they are.
Unfortunately, we are not allowed to use external libraries, so without using Boost.
Are there any ways around this?
Just to clarify, I understand that C ++ cannot initially do this. But there must be some way around this. For example, I was thinking of doing RetrieveValue (dataString1, GetType (dataString1)). This does not fix anything, because GetType can also have only one return type. But I need something like that.
I understand that this question was asked before, but in a different sense. I cannot use any obvious answers. I need something completely ready so that it is useful to me, which was not in the answers in another question.
c ++ function types overloading
Josh johnson
source share