It worked like this: std::unordered_map<std::string, std::string> x = {..}; , now I std::unordered_map<const char*, const char*, decltype(hash_func), decltype(comp_func)> x(0, hash_func, comp_func) = {..} trying to remake to std::unordered_map<const char*, const char*, decltype(hash_func), decltype(comp_func)> x(0, hash_func, comp_func) = {..} further syntax error. Or maybe it will turn out functions to thrust directly into <> template?

 auto hash_func = [](const char* x) { return (size_t)*x; }; auto comp_func = [](const char* x, const char* y) { return !strcmp(x, y); }; 
  • Show the error message. - Vlad from Moscow
  • typical heap syntax error: missing ';' before '=' syntax error: missing ';' before '{' syntax error: '=' syntax error: missing ';' before '=' syntax error: missing ';' before '{' syntax error: '=' syntax error: missing ';' before '=' syntax error: missing ';' before '{' syntax error: '=' from which nothing is unclear what is wrong =) - J. Doe
  • @. Doe And also show how your hash_func and comp_func are defined - Vlad from Moscow

1 answer 1

The problem is that you are using the wrong syntax. You have already called the constructor

 std::unordered_map<const char*, const char*, decltype(hash_func), decltype(comp_func)> x(0, hash_func, comp_func) = { /*...*/ }; ^^^^^^^^^^^^^^^^^^^^^^^^^ 

Therefore, you cannot add anything to this line.

Just put a semicolon after the parentheses, as requested by the compiler.

 std::unordered_map<const char*, const char*, decltype(hash_func), decltype(comp_func)> x(0, hash_func, comp_func); ^^^ 

Only one class constructor can be called to create an object, except for the delegation of constructors. :)

  • with a tail, what to do? can later add x.hash_func = hash_func .. the answer is that this can not be done or not?) - J. Doe
  • @ J.Doe Why do you need a tail? :) You have already indicated in brackets that you are using hash_func and comp_func. You have already passed them as arguments to the designer. :) - Vlad from Moscow
  • there in {} the initialization list is very long, if you manually drive through for then ugly, that is, I also need to pass arguments to it - J. Doe
  • @ J.Doe You must choose a single constructor. You cannot immediately select two constructors at the same time. - Vlad from Moscow