3

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've never seen it before?

1 Answer 1

5

It is a function pointer that returns a Base pointer and takes no arguments, e.g.

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

Example

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. I get that the return type is a Base*, what exactly is the (*) meant to signify?
@stackuser It's a function pointer without a name. Take a look at the linked wiki page.
@stackuser That it is a pointer, a function pointer to be precise. The parenthesis are part of the syntax for specifying a function pointer. There's no name as Jiri hinted since it is not needed.
can we add a name, for readability? std::map<std::string, Base*(*function)()> mymap;
@vincentB not in this case since it's a template argument

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.