About the little things STL

First of all ...... general definition of an own STL, then take the inheritance way better ...... avoid many problems.
Then if you want to write your own, then the problem of how to associate iterator iterator and container up:
http://users.cs.northwestern.edu/~riesbeck/programming/c++/stl-iterator-define.html#TOC19
see this website. Because I did not need to use this assignment to see.
Then a very important point is that, when inherited, inherited class to write the whole name. such as:

template<class T1, class T2, class T3 = greater<T1> >
class MyMultimap :public multimap<T1, T2> {
public:
	void Set(T1 key, T2 value) {
		typename multimap<T1,T2>::iterator p = this->begin();
		for (; p != this->end(); ++p) {
			if (p->first == key) {
				p->second = value;
			}
		}
	}
	friend ostream& operator<<(ostream &cout, pair<T1, T2>object) {
		cout << '(' << object.first << ',' << object.second << ')' ;
		return cout;
	}
};
template <class T1, class T2,class T3=greater<pair<T1,T2> > >
ostream& operator<<(ostream &cout, pair<T1, T2> object) {
	cout << '(' << object.first << ',' << object.second << ')' ;
	return cout;
}

This piece of code in the output when the output but will not be big to small from small to large output, I do not know why. But then to see someone else's code, found to be inherited multimap there, write:

class MyMultimap:public multimap<T1,T2,T3>

In this case, you will default than the size of the function is greater, or else directly multimap default is that there's less a function. note.

Guess you like

Origin blog.csdn.net/weixin_44288817/article/details/89059326