associative containers

what mean this statement: operator int() const {return a;}
How it works in code below:
#include <iostream>
#include <set>
#include <vector>
using namespace std;
class A {
int a;
public:
A(int a):a(a){}
int getA() const { return a;}
operator int() const{return a;}
};
int main(){
A mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
vector<A> v(mynumbers, mynumbers+7);
set<A> s1(v.begin(),v.end()); //LINE I
s1.insert(v.begin(),v.end());
s1.erase(s1.lower_bound(3),s1.upper_bound(6));
for(set<A>::iterator i=s1.begin();i!= s1.end(); i++) {
cout<<i->getA()<<" ";
}
cout<<endl;
return 0;
}
That is user-defined conversion. See
http://en.cppreference.com/w/cpp/language/cast_operator
Thank You keskiverto !
Topic archived. No new replies allowed.