我正在尝试创建一个 unordered_map,它有一个整数作为键,一个 Transition 对象作为值......这是我所拥有的:
实例化
unordered_map<int, Transition> transitions;
过渡类声明:
class Transition{
public:
Transition(int n, char r, char m);
~Transition();
int getNextState();
char getReplacement();
char getMovement();
private:
int nextState;
char replacement;
char movement;
};
向 map 添加过渡
// Create transition object
Transition t(r,b,x);
transitions[keyForMap] = t;
我收到这个错误:
/usr/include/c++/4.7/bits/hashtable_policy.h:445:24: error: no matching function for call to ‘Transition::Transition()’
/usr/include/c++/4.7/bits/hashtable_policy.h:445:24: note: candidates are:
In file included from ball_p1.cpp:6:0:
Transition.h:4:3: note: Transition::Transition(int, char, char)
Transition.h:4:3: note: candidate expects 3 arguments, 0 provided
Transition.h:1:7: note: constexpr Transition::Transition(const Transition&)
Transition.h:1:7: note: candidate expects 1 argument, 0 provided
我是否需要以某种方式指定构造函数在实例化中某处采用的参数?我究竟做错了什么?感谢您提前提供帮助。
最佳答案
我总是使用 map.insert(std::make_pair(keyForMap, transition));
。
关于c++ - 尝试将对象放入 unordered_map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28376803/