std::list custom allocator issues

Discussion in 'C++' started by ranin02, Aug 27, 2007.

  1. ranin02

    ranin02 Guest

    Hi,

    We have a list derived from std::list that has a custom allocator
    derived from std::allocator. This was originally written using VC++
    6.0 which required a workaround for the fact that 6.0 did not support
    nested templates classes, so could not use the rebind struct.
    Instead, a _Charalloc function was implemented.

    Now that we are moving to VS 2005, this is no longer working so I need
    to implement using the rebind struct. So I did this, and changed the
    charalloc function to be a regular allocate function. But I am
    running into problems, which I am thinking may be partly because the
    allocator is taking two template parms. The template is declared as
    follows:

    template <class Ty, class _Node>
    class CObjectPoolListAlloc : public std::allocator<Ty>

    And I declared the rebind struct as follows:

    template<class _Other>
    struct rebind {
    typedef CObjectPoolListAlloc<_Other, _Node> other;
    };

    And then I changed from using charalloc to an allocator declared as
    follows:
    _Node* allocate(size_type _N)

    I am getting this error from the compiler:
    error C2440: 'initializing' : cannot convert from
    'std::_List_nod<_Ty,_Alloc>::_Node *' to
    'std::_List_nod<_Ty,_Alloc>::_Node *'

    Any thoughts?

    Thanks,
    Sherri
     
    ranin02, Aug 27, 2007
    #1
    1. Advertising

  2. ranin02

    ranin02 Guest

    I got past that part realizing I needed to return pointer, not
    _Nodeptr, but now have a puzzling error. I am seeing the following
    error

    error C2664:
    'CObjectPoolListAlloc<Ty,_Node>::CObjectPoolListAlloc(const
    CObjectPoolListAlloc<Ty,_Node> &) throw()' : cannot convert parameter
    1 from 'CObjectPoolListAlloc<Ty,_Node>' to 'const
    CObjectPoolListAlloc<Ty,_Node> &'

    And the error is actually being given within the STL list code here:
    _List_ptr(_Alloc _Al)
    : _List_nod<_Ty, _Alloc>(_Al), _Alptr(_Al)

    Why on earth would it not be able to convert to a const ref? Note
    that CObjectPoolListAlloc does not in fact define a copy constructor,
    but defaults to the base class. This code compiled fine before the
    upgrade and my attemp to implement Rebind. Please forgive me if this
    is a stupid question.
     
    ranin02, Aug 27, 2007
    #2
    1. Advertising

  3. ranin02

    ranin02 Guest

    Problem is solved, seems copy constructor is now required where it was
    sufficient to use base class implementation in 6.0

    So nevermind!
     
    ranin02, Aug 27, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gernot Frisch

    std::vector allocator?

    Gernot Frisch, Jul 21, 2004, in forum: C++
    Replies:
    4
    Views:
    3,270
    Gernot Frisch
    Jul 21, 2004
  2. ScOe
    Replies:
    0
    Views:
    1,602
  3. Mark P

    std::pair allocator?

    Mark P, Apr 27, 2005, in forum: C++
    Replies:
    6
    Views:
    1,334
    Rolf Magnus
    Apr 27, 2005
  4. Chris Thomasson

    allocator alignment issues...

    Chris Thomasson, Aug 22, 2007, in forum: C++
    Replies:
    1
    Views:
    370
    Chris Thomasson
    Aug 22, 2007
  5. Replies:
    3
    Views:
    3,139
Loading...

Share This Page