Bonjour,

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include <iostream>
#include <string>
#include <map>
#include <memory>
 
using namespace std;
 
class Toto
{
  public:
    Toto(int a){/* nothing*/}
 
    void pouet(void){cout << "coucou" << endl;}
};
 
int main(void)
{
  map<string, auto_ptr<Toto> > tyty;
 
  tyty["ee"].reset(new Toto(4));
  tyty["ee"] -> pouet();
 
  return 0;
}
et l'erreur de compilation (sous gcc) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
/usr/include/c++/3.3.3/bits/stl_pair.h: In constructor `std::pair<_T1, 
   _T2>::pair(const _T1&, const _T2&) [with _T1 = const std::string, _T2 = 
   std::auto_ptr<Toto>]':
/usr/include/c++/3.3.3/bits/stl_map.h:319:   instantiated from `_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = std::string, _Tp = std::auto_ptr<Toto>, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::auto_ptr<Toto> > >]'
t1.cc:21:   instantiated from here
/usr/include/c++/3.3.3/bits/stl_pair.h:84: error: passing `const 
   std::auto_ptr<Toto>' as `this' argument of `std::auto_ptr<_Tp>::operator 
   std::auto_ptr_ref<_Tp1>() [with _Tp1 = Toto, _Tp = Toto]' discards 
   qualifiers
/usr/include/c++/3.3.3/bits/stl_pair.h: In constructor `std::pair<_T1, 
   _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = const std::string, _U2 = 
   std::auto_ptr<Toto>, _T1 = const std::string, _T2 = std::auto_ptr<Toto>]':
/usr/include/c++/3.3.3/bits/stl_construct.h:78:   instantiated from `void std::_Construct(_T1*, const _T2&) [with _T1 = std::pair<const std::string, std::auto_ptr<Toto> >, _T2 = std::pair<const std::string, std::auto_ptr<Toto> >]'
/usr/include/c++/3.3.3/bits/stl_tree.h:618:   instantiated from `std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(const _Val&) [with _Key = std::string, _Val = std::pair<const std::string, std::auto_ptr<Toto> >, _KeyOfValue = std::_Select1st<std::pair<const std::string, std::auto_ptr<Toto> > >, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::auto_ptr<Toto> > >]'
/usr/include/c++/3.3.3/bits/stl_tree.h:985:   instantiated from `std::_Rb_tree_iterator<_Val, _Val&, _Val*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, const _Val&) [with _Key = std::string, _Val = std::pair<const std::string, std::auto_ptr<Toto> >, _KeyOfValue = std::_Select1st<std::pair<const std::string, std::auto_ptr<Toto> > >, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::auto_ptr<Toto> > >]'
/usr/include/c++/3.3.3/bits/stl_tree.h:1068:   instantiated from `std::_Rb_tree_iterator<_Val, _Val&, _Val*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(std::_Rb_tree_iterator<_Val, _Val&, _Val*>, const _Val&) [with _Key = std::string, _Val = std::pair<const std::string, std::auto_ptr<Toto> >, _KeyOfValue = std::_Select1st<std::pair<const std::string, std::auto_ptr<Toto> > >, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::auto_ptr<Toto> > >]'
/usr/include/c++/3.3.3/bits/stl_map.h:364:   instantiated from `typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::insert(typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, _Alloc>::iterator, const std::pair<const _Key, _Tp>&) [with _Key = std::string, _Tp = std::auto_ptr<Toto>, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::auto_ptr<Toto> > >]'
/usr/include/c++/3.3.3/bits/stl_map.h:319:   instantiated from `_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = std::string, _Tp = std::auto_ptr<Toto>, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::auto_ptr<Toto> > >]'
t1.cc:21:   instantiated from here
/usr/include/c++/3.3.3/bits/stl_pair.h:88: error: passing `const 
   std::auto_ptr<Toto>' as `this' argument of `std::auto_ptr<_Tp>::operator 
   std::auto_ptr_ref<_Tp1>() [with _Tp1 = Toto, _Tp = Toto]' discards 
   qualifiers
une idée d'ou peut venir l'erreur ?

Luther