473,761 Members | 3,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CObjectPoolList Alloc : public std::allocator< Ty>

And I declared the rebind struct as follows:

template<class _Other>
struct rebind {
typedef CObjectPoolList Alloc<_Other, _Nodeother;
};

And then I changed from using charalloc to an allocator declared as
follows:
_Node* allocate(size_t ype _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 3926
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:
'CObjectPoolLis tAlloc<Ty,_Node >::CObjectPoolL istAlloc(const
CObjectPoolList Alloc<Ty,_Node& ) throw()' : cannot convert parameter
1 from 'CObjectPoolLis tAlloc<Ty,_Node >' to 'const
CObjectPoolList Alloc<Ty,_Node& '

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

Why on earth would it not be able to convert to a const ref? Note
that CObjectPoolList Alloc 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
9318
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 instantiated and keeping track of the elements through iterator logic. This seems a little messy to me though. I'm sure the guys who created the STL must have a speedier method. How do you guys clear and reuse a std::list multiple times with as...
14
5633
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 storing vertices of an arbitrary n-ary tree where a vertex contain pointers to its parent / children. These parent / child vertices need to stay put if we've got pointers to them somewhere! Am I correct in my assertion?
2
6028
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 header file has the following inside the class definition: private:
1
7298
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: Creating library Release/fnimqcmd.lib and object Release/fnimqcmd.exp CoIMQCmd.obj : error LNK2001: unresolved external symbol
7
2975
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{ Contents cn; list < BTree_node < Contents children; ........
8
3422
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
1730
by: Javier | last post by:
Hi all, I have this code: class A { std::list<Bm_observadores; void function() {
3
2528
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 non-const reference of type 'std::list<HostID, std::allocator<HostID&' from a temporary of type 'std::list<HostID, std::allocator<HostID*' helpers.cpp:99: error: in passing argument 1 of `void
11
4168
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' still points to list1::end(). 2) 'iter' now points to list2::end().
0
9353
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10123
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9909
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5241
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2765
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.