Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using std::function in std::map

I want use a std::function in std::map, follow the code:

#include <functional>
#include <map>

class MyClass {
    ...
    std::function<void()> Callback();
    std::map<std::string, Callback> my_map;
    ...
}

std::map receive a Key and a T, but a not knew whats mistake in my code, him no access the std::map functions(insert, end, find...)

Using typedef, him run.But why std::function not run?

I firts place: whats the problem?

Before: How to solve it? --code sample please =D;

Thanks by help

like image 749
user3854612 Avatar asked Mar 21 '15 15:03

user3854612


1 Answers

You've declared Callback to be a function (returning std::function), not a type. You need a type to declare what you're storing in the map. I guess you want

typedef std::function<void()> Callback;
like image 123
Mike Seymour Avatar answered Nov 10 '22 13:11

Mike Seymour