Reputation: 73
I have the following code:
#include <memory>
#include <functional>
#include <string>
#include <unordered_map>
typedef std::shared_ptr<std::string> StrPtr;
auto hash1 = [](const StrPtr ptr) { return std::hash<std::string>()(*ptr); };
...
class Actor {
...
private:
std::unordered_multimap<StrPtr,StrPtr,decltype(hash1)> set(250000,hash1);
...
};
If I want to compile it I get the following error:
Actor.hpp:15:68: error: expected identifier before numeric constant
std::unordered_multimap<StrPtr,StrPtr,decltype(hash1)> set(250000,hash1);
^
Actor.hpp:15:68: error: expected ‘,’ or ‘...’ before numeric constant
Looking at the constructor definition of unordered_multimap, there seems to be no contradiction to my initialization. What is the problem here?
I compiled with gcc 4.8
Upvotes: 0
Views: 525
Reputation: 238401
Regular parentheses are not allowed in a brace-or-equals initializer. Use curly brackets:
std::unordered_multimap<StrPtr,StrPtr,decltype(hash1)> set{250000,hash1};
This limitation prevents ambiguity that would arise in some cases with function declarations, which use parenthesis.
Upvotes: 1