一元“运算符”:“type”不定义此运算符或转换为预定义运算符可接受的类型。
在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;
}但是,错误仍然存在。我想知道是否有解决办法。
发布于 2018-10-20 03:51:40
当您以您想要的方式插入std::map时,您应该插入一个std::pair<key_type, value_type>,而不是作为一个参数的键,将一个值作为第二个参数。
以下是调用map::insert的两种方法
intvmap.insert(std::make_pair(*it, mirror));或者使用大括号初始化器:
intvmap.insert({*it, mirror});https://stackoverflow.com/questions/52902149
复制相似问题