473,386 Members | 1,706 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,386 software developers and data experts.

help with STL compiler error

In my code I use something like:

typedef std::list<Edge*,g_mm_Alloc<Edge*> > EdgeList;

and then instantiate some EdgeList objects. Here Edge is a previously
defined class and g_mm_Alloc<T> is a previously defined custom STL
allocator template.

Trying to compile on a Sun system I get the following error:

"/opt/SUNWspro/prod/include/CC/Cstd/./memory", line 488: Error: Using
static_cast to convert from newScan::Edge** to std::list<newScan::Edge*,
g_mm_Alloc<newScan::Edge*>>::__list_node_buffer* not allowed.
"/opt/SUNWspro/prod/include/CC/Cstd/./list", line 132: Where: While
instantiating "std::allocator_interface<g_mm_Alloc<newScan::Edge *>,
std::list<newScan::Edge*,
g_mm_Alloc<newScan::Edge*>>::__list_node_buffer>:: allocate(unsigned,
std::list<newScan::Edge*,
g_mm_Alloc<newScan::Edge*>>::__list_node_buffer*)" .
"/opt/SUNWspro/prod/include/CC/Cstd/./list", line 132: Where:
Instantiated from non-template code.

Looking for line 488 of ".../memory" I see:

//
// allocator_interface provides all types and typed functions. Memory
// allocated as raw bytes using the class provided by the Allocator
// template parameter. allocator_interface casts appropriately.
//
// Multiple allocator_interface objects can attach to a single
// allocator, thus allowing one allocator to allocate all storage
// for a container, regardless of how many types are involved.
//
// The only real restriction is that pointer and reference are
// hard coded as T* and T&. Partial specialization would
// get around this.
//
template <class Allocator,class T>
class allocator_interface
{
public:
typedef Allocator allocator_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE size_type;
typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE difference_type;
typedef void* void_pointer;
typedef const void* const_void_pointer;

protected:
allocator_type alloc_;

public:
allocator_interface() _RWSTD_THROW_SPEC_NULL { ; }
allocator_interface(const Allocator& a) _RWSTD_THROW_SPEC_NULL
: alloc_(a) { ; }

pointer address (T& x)
{
return _RWSTD_STATIC_CAST(pointer,&x);
}

size_type max_size () const
{
return alloc_.max_size(sizeof(T));
}

pointer allocate(size_type n, pointer p = 0)
{
return _RWSTD_STATIC_CAST(pointer,alloc_.allocate(n*sizeo f(T),p));
// LINE 488 IS IMMEDIATELY ABOVE
}

void deallocate(pointer p, size_type n)
{
alloc_.deallocate(p,n*sizeof(T));
}

inline void construct(pointer p, const T& val);

inline void destroy(T* p);

};

I have no idea what to make of this. It looks like it's trying to cast
a list node to a T*, where it ought to be using some sort of rebind
mechanism. Any help or guidance would be greatly appreciated.

Thanks,
Mark
Jul 23 '05 #1
4 2147
Mark P wrote:
In my code I use something like:

typedef std::list<Edge*,g_mm_Alloc<Edge*> > EdgeList;
This is a list of _pointers_ to newScan::Edge objects. Does it really
make sense in your case to use an allocator to allocate pointers (not
pointed-to objects)?
and then instantiate some EdgeList objects. Here Edge is a previously defined class and g_mm_Alloc<T> is a previously defined custom STL
allocator template.

Trying to compile on a Sun system I get the following error:

"/opt/SUNWspro/prod/include/CC/Cstd/./memory", line 488: Error: Using static_cast to convert from newScan::Edge** to std::list<newScan::Edge*, g_mm_Alloc<newScan::Edge*>>::__list_node_buffer* not allowed.
Your RogueWave allocator seemingly doesn't like pointers as objects.
Looking for line 488 of ".../memory" I see:

template <class Allocator,class T>
class allocator_interface
{ [...]
pointer allocate(size_type n, pointer p = 0)
{
return _RWSTD_STATIC_CAST(pointer,alloc_.allocate(n*sizeo f(T),p)); // LINE 488 IS IMMEDIATELY ABOVE
}
_RWSTD_STATIC_CAST expands to static_cast (see above) which doesn't
work for pointers. They probably should have used a reinterpret_cast or
a C-style cast here. I'm not entirely sure though ...

[...] };

I have no idea what to make of this. It looks like it's trying to cast a list node to a T*, where it ought to be using some sort of rebind
mechanism.
They try to cast a newScan::Edge** to a ...__list_node_buffer*
(probably a void*). The static_cast only works for g_mm_Alloc<Edge>,
not for g_mm_Alloc<Edge*>. In the former case you would static_cast a
newScan::Edge* to a ...__list_node_buffer*.
Any help or guidance would be greatly appreciated.


Most probably you don't need the g_mm_Alloc<Edge*> thing, just
std::list<Edge*>.

Abe

Jul 23 '05 #2
ab*********@spambob.com wrote:
Mark P wrote:
In my code I use something like:

typedef std::list<Edge*,g_mm_Alloc<Edge*> > EdgeList;

This is a list of _pointers_ to newScan::Edge objects. Does it really
make sense in your case to use an allocator to allocate pointers (not
pointed-to objects)?


Why not? He stores pointers to Edge, so he allocates them...

Just a thought.
[...]

Jul 23 '05 #3
ab*********@spambob.com wrote:
Mark P wrote:
In my code I use something like:

typedef std::list<Edge*,g_mm_Alloc<Edge*> > EdgeList;

This is a list of _pointers_ to newScan::Edge objects. Does it really
make sense in your case to use an allocator to allocate pointers (not
pointed-to objects)?


Well my understanding is that a list of Edge* is unlikely to ever
actually allocate space for an Edge* but instead would allocate space
for a list node type, each instance of which would include an Edge* and
other information (prev, next node*, etc.) too. In any case, I don't
see anything non-compliant about this usage.


Most probably you don't need the g_mm_Alloc<Edge*> thing, just
std::list<Edge*>.


But I really do. The memory needs to come from g_mm_Alloc.
Jul 23 '05 #4
Mark P wrote:
In my code I use something like:

typedef std::list<Edge*,g_mm_Alloc<Edge*> > EdgeList;

and then instantiate some EdgeList objects. Here Edge is a previously
defined class and g_mm_Alloc<T> is a previously defined custom STL
allocator template.

Trying to compile on a Sun system I get the following error:

I think I've got this sorted out. This allocator interface wraps an
allocator which has no knowledge of the type for which it allocates, it
just returns void* to allocated memory. To make this work, I simply
modified max_size, allocate, and deallocate within my custom allocator,
such that all of these work in terms of void* and numbers of allocated
words rather than T* and numbers of allocated T objects.

Mark

//
// allocator_interface provides all types and typed functions. Memory
// allocated as raw bytes using the class provided by the Allocator
// template parameter. allocator_interface casts appropriately.
//
// Multiple allocator_interface objects can attach to a single
// allocator, thus allowing one allocator to allocate all storage
// for a container, regardless of how many types are involved.
//
// The only real restriction is that pointer and reference are
// hard coded as T* and T&. Partial specialization would
// get around this.
//
template <class Allocator,class T>
class allocator_interface
{
public:
typedef Allocator allocator_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE size_type;
typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE difference_type;
typedef void* void_pointer;
typedef const void* const_void_pointer;

protected:
allocator_type alloc_;

public:
allocator_interface() _RWSTD_THROW_SPEC_NULL { ; }
allocator_interface(const Allocator& a) _RWSTD_THROW_SPEC_NULL
: alloc_(a) { ; }

pointer address (T& x)
{
return _RWSTD_STATIC_CAST(pointer,&x);
}

size_type max_size () const
{
return alloc_.max_size(sizeof(T));
}

pointer allocate(size_type n, pointer p = 0)
{
return _RWSTD_STATIC_CAST(pointer,alloc_.allocate(n*sizeo f(T),p));
// LINE 488 IS IMMEDIATELY ABOVE
}

void deallocate(pointer p, size_type n)
{
alloc_.deallocate(p,n*sizeof(T));
}

inline void construct(pointer p, const T& val);

inline void destroy(T* p);

};

I have no idea what to make of this. It looks like it's trying to cast
a list node to a T*, where it ought to be using some sort of rebind
mechanism. Any help or guidance would be greatly appreciated.

Thanks,
Mark

Jul 23 '05 #5

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

Similar topics

0
by: Jagdeesh | last post by:
Hai Colleagues, I am using Tomcat 4.1.24 and JDK 1.4.0_03 in my winXP machine. I've transferred a set of folders(containing jsp files) into tomcat's webapps directory(to /webapps/bob ,...
11
by: Don Bruder | last post by:
Got a stumper here. I imagine that for someone experienced in C++, this is too pathetic for words. For a rookie, using this project as a sort of "midterm exam" in his self-taught "how to program in...
4
by: Piotr Sawuk | last post by:
I'm a newbie in the world of c++, and I am used to learn a programming language simply by programming. Unfortunately I where unable to find any useful helpfile for this language, in which such...
8
by: Bshealey786 | last post by:
Okay im doing my final project for my first computer science class(its my major, so it will be my first of many), but anyway im a beginner so im not to great with C++ yet. Anyway this is the error...
3
by: Steve Long | last post by:
Hello, I have a VB.NET class that raises a MapSet event that passes an argument of type interop.MapObjects2.MapClass. I have a C# class that inherits from this VB.NET class. How can I handle the...
0
by: Ben Harper | last post by:
I am stuck using VC7 right now, so I can't test this on 7.1, but I believe it is a bug in the compiler, although I hope it isn't. Please could someone confirm this for me, prove me wrong, or suggest...
6
by: Paul | last post by:
Not sure if this is the correct place to post the problem, but trying to use the HTML help workshop and trying to create the index file automatically. Anyhow I get the error below HHC5003: Error:...
5
by: Marc Violette | last post by:
<Reply-To: veejunk@sympatico.ca> Hello, I'm hoping someone can help me out here... I'm a beginner ASP.NET developper, and am trying to follow a series of exercises in the book entitled...
2
by: Raghunadhan | last post by:
pLS HELP ME HOW THIS ERROR OCCURED . WHEN RUNNING JSP PAGE BY USING TOMCAT APACHE.... org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: -1 in...
30
by: Anarki | last post by:
The following is the program i am trying to compile //restrict.c #include <stdio.h> int main() { char arr = "Qualifiers" char * restrict p = arr; int i = 0; for(; i < 10; ++i)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.