0

The problem is something like:

I have a function named ADD_TWO(int,int);, now in the program, I want to create its alias keeping the previous function untouched. Something like ADD_TWO_NUMBERS(int,int);. i.e if I call ADD_TWO_NUMBERS it should execute ADD_TWO.

I want to have an Alias for the function.

frogatto
  • 28,539
  • 11
  • 83
  • 129
Mukesh Pareek
  • 33
  • 1
  • 7

3 Answers3

0
int ADD_TWO(int a, int b)
{
    return a+b;
}

int main()
{
    int (*ADD_TWO_NUMBERS)(int, int) = ADD_TWO;
    int result = ADD_TWO_NUMBERS(10, 12);  //or (*ADD_TWO_NUMBERS)(10, 12)
    cout<<"  Result :- "<<result<<endl;
    return 0;
}

Use Function pointers

instance
  • 1,366
  • 15
  • 23
0

Aside from using function pointers you can use function-like macros. Try something like

#define ADD_TWO_NUMBERS(x,y) ADD_TWO(x,y)
Jawn Doe
  • 21
  • 5
0

Since this question has tag and assuming you're using a c++11 compiler, then:

int ADD_TWO(int a, int b)
{
    return a+b;
}

int main()
{
    auto ADD_TWO_NUMBERS = ADD_TWO;
    int result = ADD_TWO_NUMBERS(10, 12);
    cout << "  Result :- " << result << endl;
    return 0;
}
frogatto
  • 28,539
  • 11
  • 83
  • 129