samedi 3 juillet 2021

One function that can be called with multiple function psuedonames/synonyms

First of all, this is completely for fun, and has little practical purpose, I guess.

What I'm attempting to do is. have 1 function, but I can call it with different function psuedonames.

so instead of doing:

calculate_result(int x, int y);

I could also do:

calculate_answer(int x, int y);

or I could even do:

calculation(int x, int y);

all of these would lead to this same function:

int calculate(int x, int y)
{
answer = x + y;
return answer;
}

so

int main()
{
int num1 = 5;
int num2 = 5;
int output =  (calculate_result(num1, num2) + calculate_answer(num1, num2) + calculation(num1, num2));
cout << output;
return 0;

}

I thought templates might be able to be used for this purpose? Is there any way of doing this?

Aucun commentaire:

Enregistrer un commentaire