Search code examples
c++function-pointersusing

What is "using" doing in this instance, and what is being stored?


I have the following class:

class Foo{

}

class Bar{
public:

     using meth = Foo* (*)(int a, std::string b);
}

Can someone explain what the line means:

     using meth = Foo* (*)(int a, std::string b);

It seems to me that this is a way of storing a pointer to a constructor or something. If someone can explain, I would appreciate it.

Please feel free to edit the question itself to make it more descriptive - if I knew what this code did, I wouldn't ask the question.


Solution

  • The line

    using meth = Foo* (*)(int a, std::string b);
    

    makes meth a shorthand (type alias) for the lengthy function pointer type declaration.

    It can be used like:

    Foo* bar(int a, std::string b);
    
    meth baz = bar;