【发布时间】:2010-02-24 19:35:05
【问题描述】:
修复以下代码最优雅的方法是什么:
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef map< int, int > row_t;
typedef vector< row_t > board_t;
typedef row_t::iterator area_t;
bool operator< ( area_t const& a, area_t const& b ) {
return( a->first < b->first );
};
int main( int argc, char* argv[] )
{
int row_num;
area_t it;
set< pair< int, area_t > > queue;
queue.insert( make_pair( row_num, it ) ); // does not compile
};
解决它的一种方法是将 less你不应该这样做。)
namespace std {
bool operator< ( area_t const& a, area_t const& b ) {
return( a->first < b->first );
};
};
另一个明显的解决方案是定义小于 但我想避免这种情况并成为 只能为一个元素定义运算符 未定义的对。
【问题讨论】:
-
这是一个有趣的名字,你的设置在那里;)
-
名字里有什么?任何其他名字的玫瑰都会闻起来很香。
标签: c++ stl operators operator-keyword