I would like to learn C ++ 11 a little more, so I wrote the simplest possible initializer_list test that I knew, but inside the template it is a βfreeβ function, and I get this error whenever I compile it (clang ++ for pretty formatting)
/home/alex/repo/mine/mlcppl/test/utiltest1.cc:16:3: error: no matching function for call to 'makevec' mlcppl::makevec<string> ({"alex", "herrmann"});
Here is the code:
namespace mlcppl{ template<typename Tp> vector<Tp> makevec (initializer_list<Tp> initlist) { vector<Tp> vt; for(Tp x : initlist) { vt.insert(vt.end(), x); } return vt; } }
and here it is called:
#include <util.hh> int main() { vector<string> vc; vc = makevec<string> ({"alex", "herrmann"}); return 0; }
I have no clue why this will happen, Any suggestions?
source share