C++ C++;:将结构插入集合时出错
我试图在ITK类中的C++ C++;:将结构插入集合时出错,c++,struct,set,C++,Struct,Set,我试图在ITK类中的集合中插入结构 结构在类中定义如下: struct PixType { IndexType Index; PixelType Value; bool operator <(const PixType&rhs) { return (double)Value < (double)rhs.Value; } }; 但是,当我创建集合并尝试插入元素时 // Create set std::set< Pix
集合中插入结构
结构在类中定义如下:
struct PixType {
IndexType Index;
PixelType Value;
bool operator <(const PixType&rhs) {
return (double)Value < (double)rhs.Value;
}
};
但是,当我创建集合并尝试插入元素时
// Create set
std::set< PixType > MySet;
// Create something to insert into set
PixType LeftPixel;
LeftPixel.Index = qualIt.GetIndex( left );
LeftPixel.Value = qualIt.GetPixel( left );
// Try to insert into set
MySet.insert( LeftPixel ); // error: invalid operands to binary expression
//创建集合
std::setMySet;
//创建要插入到集合中的内容
像素型左像素;
LeftPixel.Index=qualIt.GetIndex(左);
LeftPixel.Value=qualIt.GetPixel(左);
//试着插入到集合中
MySet.insert(LeftPixel);//错误:二进制表达式的操作数无效
…我得到一个无效操作数到二进制表达式的错误。我还尝试了inline
ing操作符需要是常量,以便它可以应用于集合的常量元素:
bool operator <(const PixType&rhs) const
^^^^^
bool接线员非常感谢,好像已经完成了!(3分钟内无法接受答案…)
bool operator <(const PixType&rhs) const
^^^^^
bool operator <(const PixType&lhs, const PixType&rhs)