i'm observing compilation error "error: not convert '{{{&foo::print_add}, {&x::print}}}' '' 'std::vector'" in below code.
am doing vector insertion wrong? btw don't want use push_back method. possible insert using '='. i'm having feeling it's syntactical mistake not able find it.
when googled, found there bug in earlier versions of gcc. i'm using 4.8.1 i'm assuming library i'm using should include fix.
#include <functional> #include <iostream> #include <vector> struct foo { foo(int num) : num_(num) {} void print_add(int i) const { std::cout << num_+i << '\n'; } int num_; }; struct x { void print() { std::cout << "i'm in x "<<std::endl; } }; struct xxx { std::function<void(const foo&,int)> a; std::function<void(const x&)> b; }; int main() { std::vector<xxx> vec = { { {&foo::print_add}, {&x::print} } }; }
x::print non-const member function, , therefore pointer cannot used initialize std::function<void(const x&)>.
Comments
Post a Comment