Passing a parameter as refrence ( & ) and "Invalid use of member" - error

I am trying the pass the address of a map into the compare object that has been instantiated with in a map. I am getting this error "Invalid use of member(did you forget the '&' ?)

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 '&' ?)"
	  }
 };


do I have to translate S_ as it is moved from Xmap 'set' to map_sort 'setM' ? or is the current code correct?
I don't know anything about your map class. Are you deriving from the STL map, or your own? At any rate, what is the type of the member key_comp (though I have suspicions)?

Also, um... what is the purpose of your Xmap class?

-Albatross
Last edited on
can you let me know in

template <class T, class U, class C>
why this extra c class (type ) ?
Topic archived. No new replies allowed.