I am trying to wrap several constructors in lambdas in order to store those in a vector and then loop over it:
using move_constructor = std::function<Move*(Site,vector<Move*>*, int)>;
vector<move_constructor> diff_plane_list = {
[](Site p_site, vector<Move*>* move_list, int latLen) {
return new Diffuse_inplane_px(p_site, move_list, latLen);
},
[](Site p_site, vector<Move*>* move_list, int latLen) {
return new Diffuse_inplane_mx(p_site, move_list, latLen);
},
...
}
However, when trying to compile it using g++-5.3, I get the following error message for each item in the vector:
/tmp/ccc2A87Z.o: In function `{lambda(std::tuple<int, int, int>, std::vector<Move*, std::allocator<Move*> >*, int)#1}::operator()(std::tuple<int, int, int>, std::vector<Move*, std::allocator<Move*> >*, int) const':
All_moves.cc:(.text+0x5e): undefined reference to `Diffuse_inplane_px::Diffuse_inplane_px(std::tuple<int, int, int>, std::vector<Move*, std::allocator<Move*> >*, int)'
So the vector<Move*>*
gets somehow cast to vector<Move*, std::allocator<Move*> >*
? How should I do this properly? Is there a better way to loop over a list of constructors and store the pointers to the created objects in a vector?
Aucun commentaire:
Enregistrer un commentaire