Search code examples
c++functionparameter-passingcall

How can I call a function using parameter list in c++?


I have a unchangeable function like

void foo(int a, const char* b, int c)
{
}

and I want to call this function as follows:

void main()
{
    paramList.add(1);//adding int
    paramList.add("hello world"); //adding string
    paramList.add(3);//adding int
    foo(paramlist);

}

How can I call foo function as in example?


Solution

  • You can create an overloaded function that takes the paramlist object, and extracts the items to call the proper foo function with its actual arguments.