Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expression having type 'const CompareVPtrs' would lose some const-volatile qualifiers in order to call

Tags:

c++

stl

I am implementing fifteen puzzle console game in C++, raises the following error

Error 4  error C3848: expression having type 'const CompareVPtrs' would lose some
   const-volatile qualifiers in order to call 
   'bool CompareVPtrs::operator ()(Vertex *,Vertex *)'    
   c:\program files\microsoft visual studio 11.0\vc\include\xfunctional   
  324 1  puzzle15

This is my structure

struct CompareVPtrs: public binary_function<Vertex*, Vertex*, bool>
{
    bool operator()( Vertex *lhs, Vertex *rhs)
    {
        return equal((int *)lhs->state, (int *)lhs->state+16,
            (int *)rhs->state);
    }
}
CompareVP;

The full game source code https://gist.github.com/sunloverz/7338003

like image 958
Aydar Omurbekov Avatar asked Nov 06 '13 15:11

Aydar Omurbekov


People also ask

Which expression would lose some const-volatile qualifiers to call'function'?

In this article expression having type 'type' would lose some const-volatile qualifiers in order to call 'function' A variable with a specified const-volatile type can only call member functions defined with same or greater const-volatile qualifications.

Can a variable with a specified const-volatile type call member functions?

A variable with a specified const-volatile type can only call member functions defined with same or greater const-volatile qualifications. The following samples generate C3848:

What does code that no longer compiles cleanly mean?

} Show activity on this post. Code that no longer compiles cleanly because of compiler conformance improvements or changes in the standard. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid …


1 Answers

It means your comparison operator needs to be const:

bool operator()( Vertex *lhs, Vertex *rhs) const
{ //                                       ^^^^^
  ....
}
like image 135
juanchopanza Avatar answered Oct 24 '22 17:10

juanchopanza