unary 'operator' : 'type' does not define this operator or a conversion to a type acceptable to the predefined operator
在c++中使用TriMesh::VertexHandle作为map的键值时出现问题。
map<TriMesh::VertexHandle, TriMesh::VertexHandle> intvmap;
for (vector<TriMesh::VertexHandle>::iterator it = oldVertices.begin(); it != oldVertices.end(); ++it){
bool isInternal = mesh.property(vIsInternal, *it);
if (isInternal) {
TriMesh::Point pos = mesh.point(*it);
TriMesh::VertexHandle mirror = mesh.add_vertex(pos - z * 2 * mesh.property(vHeight, *it));
mesh.property(vHeight, mirror) = -mesh.property(vHeight, *it);
mesh.property(vIsInternal, mirror) = true;
intvmap.insert((*it), mirror);
}
}
insert() 不工作并得到上面的错误。
template<class _Iter>
void insert(_Iter _First, _Iter _Last)
{ // insert [_First, _Last) one at a time
_DEBUG_RANGE(_First, _Last);
for (; _First != _Last; ++_First)
emplace_hint(end(), *_First);
}
我认为是operator++的问题,所以我在头文件中添加了代码
TriMesh::VertexHandle& operator++(TriMesh::VertexHandle& vh){ //++A
vh.__increment();
return vh;
}
TriMesh::VertexHandle operator++(TriMesh::VertexHandle & p_oRight, int) // A++
{
TriMesh::VertexHandle & copy = p_oRight;
copy.__increment();
return copy;
}
但是,错误依然存在。 我想知道是否有解决方案。
最佳答案
当您插入 std::map
时按照您的预期方式,您应该插入 std::pair<key_type, value_type>
,不是键作为一个参数,而是值作为第二个参数。
这里有两种方式调用map::insert
:
intvmap.insert(std::make_pair(*it, mirror));
或者使用大括号初始化器:
intvmap.insert({*it, mirror});
关于c++ - 一元 'operator' 没有在 C++ 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52902149/