[Solved] Call function use pointer


First of all: Your functions void my_int_func(int x) and void my_int_func2(int y) do not return anything (return type void). They just prompt the input parameters to stdout.

What you probably want is something like that

#include <iostream>

using namespace std;

int my_int_func(int x)
{
  return x;
}

int my_int_func2(int x)
{
  return x;
}

void sum(int x, int y)
{
  std::cout << x << " + " << y << " = " << (x + y) << endl;
}

int main()
{
  int (*f1)(int) = *my_int_func;
  int (*f2)(int) = *my_int_func2;
  sum(f1(1),f2(2));
}

This will hand the integer values 1 and 2 to my_int_funcand my_int_func2. They will return those values as an input for sum which will then prompt 1 + 2 = 3.

However the two functions aren’t very useful. A better and less static way would be to read the numbers from the user input as Vlad pointed out.

solved Call function use pointer