I would like to sort the code containing about a hundred expressions:
if( flag ) AddData( key, some_number ); else AddData( key, error_description );
Where adddata is overloaded like
bool AddData( int key, double value ); bool AddData( int key, const char * error );
I would like to express the code above:
AddData( key, flag? some_number : error_description );
which, of course, will not compile, because the flag value is determined at run time, and the AddData signature must be determined at compile time.
Combining both functions into something like
bool AddData( int key, bool flag, double value, const char * error );
and decide which parameter to use and which to ignore will work, but it just doesn’t look enough.
So the question is: is it possible to more efficiently allow function overloading at runtime?
source share