I defined my own structure, for example
struct element { int id; float value; }
and I use it with std::set . I want to use the set_difference algorithm (as mentioned in the previous question to determine the difference between two sets. When I try to call the code, compilation stops with the following error message:
/usr/include/c++/4.2.1/bits/stl_algobase.h:268: error: passing 'const element' as 'this' argument of 'element& element::operator=(const element&)' discards qualifiers
A minimal example might look like this:
std::set<struct element> s1; std::set<struct element> s2; std::set<struct element> s3; element e1 = { 1, 11.0 }; element e2 = { 2, 22.0 }; element e3 = { 3, 33.0 }; s1.insert(e1); s1.insert(e2); s2.insert(e2); s2.insert(e3); set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), s3.begin());
source share