C ++ factory pattern syntax

In this question, the accepted answer uses the following syntax:

typedef std::map<std::string, Base*(*)()> map_type;

      

Can someone explain what the (*) means, I haven't seen it before?

+3


source to share


1 answer


It is a function pointer that returns a pointer Base

and does not take any arguments, eg.

struct Base {};

Base* myfun() {
    return 0;
}

int main() {
    std::map<std::string, Base*(*)()> mymap;
    mymap.insert(std::make_pair("hello", myfun));
}

      



+5


source







All Articles