1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
int main()
{
map<string, int> sort_order1; // make my own sorting sequence
map<string, int> sort_order2;
load_sorting_map(sort_order1);
load_sorting_map(sort_order2);
Xmap<string, int, map_sort<string, int> > mymap5(sort_order1); // address //of sort _order1 pass through constructors to s_map.
mymap5["A"] = 1;
mymap5.set(sort_order2); // address of sort_order2 passed through Xmap //member function 'set' through map_sort member function setM to s_map.
mymap5["A"] = 1;
return 0;
}
template <class T, class U>
class map_sort
{
private:
map<T, U>& s_map;
public:
map_sort( map<T, U> &s_ ) : s_map(s_) {}
void setM( map<T, U> &s_ ) {s_map = s_; }
bool operator()(T x, T y) const { return s_map.at(x) < s_map.at(y); }
};
template <class T, class U, class C>
class Xmap : public map<T, U, C>
{
public:
Xmap(map<T, U>& s_ ) : map<T, U, C>(s_) {}
~Xmap() {}
void set(map<T, U>& s_ )
{
this->clear(); // cleared before changing sort method
this->key_comp.setM(s_); //<---- I am getting the following "error. Invaldi use of member (did you forget the '&' ?)"
}
};
|