What is an alternative way to still do function overloading


The following functions are supposed to return a random int or a random double number. However the following function overloading is illegal in C++ since the parameters of both functions are the same (they both do not pass any parameters to the function):

int getRand();

double getRand(); //ERROR!!!

One way to fix this error and have two functions to return a random int or double is to have different function names, i.e.:

int getRandInt();

double getRandDouble(); //CORRECT!

What is an alternative way to still do function overloading (having the same name for the both above functions) where one returns a random int and the other returns a random double without any errors? Write the function prototypes and explain short but briefly

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: What is an alternative way to still do function overloading
Reference No:- TGS02868536

Now Priced at $10 (50% Discount)

Recommended (94%)

Rated (4.6/5)