Only by methods STL.
Loop accecible only for print the results.
Expand|Select|Wrap|Line Numbers
- class Obj
- {
- public:
- string get_str() const;
- int get_int() const;
- private:
- Obj( string my_str_, int my_int_ );
- string my_str;
- int my_int;
- }
Expand|Select|Wrap|Line Numbers
- class Map_obj
- {
- public:
- void insert_obj( string my_str, int my_int );
- void print_ordre_by_str() const;
- void print_ordre_by_int() const;
- void del_by_int( int i );
- private:
- map<string, Obj*> my_map;
- }
Expand|Select|Wrap|Line Numbers
- void Map_obj::insert_obj( string my_str, int my_int )
- {
- Obj* ptr = new Obj( my_str, my_int );
- my_map.insert( make_pair<string> ( my_str, ptr ) );
- }
Because it's order by string by default.
Expand|Select|Wrap|Line Numbers
- map <string, Obj*>::const_iterator ptr = my_map.begin();
- while ( ptr != my_map.end() )
- {
- cout << *ptr->second << endl;
- ptr++;
- }
print_ordre_by_int() //print the Obj in order by int
and
del_by_int( int i ) //delete the Obj with searched int