Liu
Liu

Reputation: 87

unary 'operator' does not define in C++

unary 'operator' : 'type' does not define this operator or a conversion to a type acceptable to the predefined operator

Got a trouble when using TriMesh::VertexHandle as the key value of map in c++.

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() didn't work and got the error above.

    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);
    }

I think the problem is about the operator++, so I add the code in the header file

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;
}

However, the error still exists. I would like to know if there is a solution.

Upvotes: 2

Views: 2161

Answers (1)

PaulMcKenzie
PaulMcKenzie

Reputation: 35454

When you're inserting into a std::map in the way you intended, you should be inserting a std::pair<key_type, value_type>, not a key as one argument, and a value as the second argument.

Here are two ways to call map::insert:

intvmap.insert(std::make_pair(*it, mirror));

or use the brace initializer:

intvmap.insert({*it, mirror});

Upvotes: 3

Related Questions