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
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.
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:
} 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 …
It means your comparison operator needs to be const
:
bool operator()( Vertex *lhs, Vertex *rhs) const
{ // ^^^^^
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With