【发布时间】:2013-02-18 17:02:40
【问题描述】:
我正在实现的部分类如下所示:
struct Cord
{
int x_cord;
int y_cord;
Cord(int x = 0,int y = 0):x_cord(x),y_cord(y) {}
bool operator()(const Cord& cord) const
{
if (x_cord == cord.x_cord)
{
return y_cord < cord.y_cord;
}
return x_cord < cord.x_cord;
}
};
class Cell
{
};
std::map<Cord,Cell> m_layout;
上面的代码我无法编译
error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Layout::Cord'
有什么建议吗?
【问题讨论】:
-
报错信息与代码无关。上面的代码编译得很好。使用
std::string查找一些代码。还要查看编译器提供的行号。 -
@OlafDietsche 它只会编译,因为地图没有元素。一旦你尝试添加一个,它就会失败,原因很简单,
Cord没有operator<。 -
@juanchopanza 你是对的,但这并不能使错误消息适合代码。
标签: c++ map comparison key