473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

std::list custom allocator issues

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, _Nodeother;
};

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

Aug 27 '07 #1
2 3906
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>::CObjectPoolListAl loc(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.

Aug 27 '07 #2
Problem is solved, seems copy constructor is now required where it was
sufficient to use base class implementation in 6.0

So nevermind!

Aug 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: scooter | last post by:
std::list::clear() can slow down the performance of a method considerably if it is called many times a second. I have countered this problem a little by assigning a fixed size to a list when...
14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
2
by: sidaf | last post by:
Hello, I'm writing a connection management class, but I'm running into problems with the std::list template. I want to use a list to help manage my Connection objects. The ConnectionManager...
1
by: sharmadeep1980 | last post by:
Hi All, I am facing a very unique problem while compling my project in "Release" build. The project is building in DEBUG mode but giving linking error on Release build. Here is the error:...
7
by: alex221 | last post by:
In need to implement a tree structure in which every node has arbitrary number of children the following code has come into mind: using std::list; template < class Contents class Tree_node{ ...
8
by: Spoon | last post by:
Hello, Could someone explain why the following code is illegal? (I'm trying to use a list of (C-style) arrays.) #include <list> typedef std::list < int foo_t; int main() { int v = { 12, 34...
0
by: Javier | last post by:
Hi all, I have this code: class A { std::list<Bm_observadores; void function() {
3
by: Ray D. | last post by:
Hey all, I'm trying to pass a list into a function to edit it but when I compile using g++ I continue to get the following error: maintainNeighbors.cpp:104: error: invalid initialization of...
11
by: Juha Nieminen | last post by:
Assume we have this: std::list<Typelist1(10, 1), list2(20, 2); std::list<Type>::iterator iter = list1.end(); list1.swap(list2); What happens here, according to the standard? 1) 'iter'...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.