X
xqxu.pzhou
I wrote a simple allocator "myAlloc" under the g++ 3.2.3. When it is
used by Vector, it works well. But when it is used by List, the codes
have errors when compling. the error message is:
Then I added the following copy constructor to "myAlloc", now it works
well.
"template <typename U>
myAlloc(const myAlloc<U>&) {}"
I don't understand such copy constructor very well. I don't know why we
should use such copy constructor. In my opinion, this copy constructor
doesn't do anything.
In order to know the detail, I delete this copy constructor in
"myAlloc", and I also delete all parts that will call above copy
constructor in file "stl_list.h". The result is that the List works
well. it seems that the list does not need the above copy constructor
any more.
So I'm wonder why we need that copy constructor, and what's the task of
that copy constructor.
TIA.
used by Vector, it works well. But when it is used by List, the codes
have errors when compling. the error message is:
"no matching function for call to myAlloc said:::myAlloc(const myAlloc<int>&), candidates are: myAlloc<T>::myAlloc(const myAlloc<T>& ) [with T = std::_List_node<int>]".
Then I added the following copy constructor to "myAlloc", now it works
well.
"template <typename U>
myAlloc(const myAlloc<U>&) {}"
I don't understand such copy constructor very well. I don't know why we
should use such copy constructor. In my opinion, this copy constructor
doesn't do anything.
In order to know the detail, I delete this copy constructor in
"myAlloc", and I also delete all parts that will call above copy
constructor in file "stl_list.h". The result is that the List works
well. it seems that the list does not need the above copy constructor
any more.
So I'm wonder why we need that copy constructor, and what's the task of
that copy constructor.
TIA.