LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-20-2004, 10:47 AM   #1
vipinsharma
LQ Newbie
 
Registered: May 2004
Posts: 9

Rep: Reputation: 0
Exclamation Problem due to STL Library


Hi All,

I am doing Porting of my project on Linux using KDevelop 2.1.3.

While compiling my project on Linux - i am facing some errors in STL library. These errors are due to the errors which i am getting in stl library.

It is giving error :

unknown type 'allocator_type".


In the stl_list.h file where ever this user defined datatype is used - it gives error. Most of the errors are of similar nature and refer to allocator_type only.

Same kind of errors are obtained even in stl_alloc.h file.


Can any one give me direction to target the problem.

Bye
 
Old 05-20-2004, 12:53 PM   #2
bluie
LQ Newbie
 
Registered: May 2004
Location: Europe
Distribution: Mutable
Posts: 10

Rep: Reputation: 0
Hi vipinsharma!
> It is giving error :
> unknown type 'allocator_type".
I just found 'allocator_type' in the 'stl_list.h' file on my linux-system.
This gives hope.
Further the following code compiles.
Code:
#include <list>

int
main()
{
  std::list<int> aList;
  std::list<int>::allocator_type aAllocator = aList.get_allocator();

  return 0;
}
This means---as far as I see---allocator_type is usable.

Does this already help you?
Can it be that you have forgotten the 'std::list<whatever>::' before
'allocator_type'?

If you have still trouble I suggest you provide a minimal example of
the failure plus the verbatim compiler-error-message.

Ciao, bluie
 
Old 05-21-2004, 03:55 AM   #3
vipinsharma
LQ Newbie
 
Registered: May 2004
Posts: 9

Original Poster
Rep: Reputation: 0
Hi bluie,
Thanks for the response. I think i wasnt able to address the problem clearly so i am providing sufficient information now.

Exact Errors i am getting in the code are: (Some of them)

-----------------------------------------------------------------------------
typedefs.h:9:instantiated from 'std::_List_base<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from 'std::list<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from 'persistentlist<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from here
stl_alloc.h:844:No class template named 'rebind' in

stl_list.h:211:instantiated from std::_List_alloc_base<char*, AllocatorInterface<char*>,false>
typedefs.h:9:instantiated from 'std::_List_base<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from 'std::list<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from 'persistentlist<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from here
stl_alloc.h:844:No class template named 'rebind' in

typedefs.h:9:instantiated from 'std::_List_base<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from 'std::list<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from 'persistentlist<CCktElem*,AllocatorInterface<CCktElem*>>
typedefs.h:9:instantiated from here
stl_list.h:211:no type named 'allocator_type' in
stl_list.h:190:no type named 'allocator_type' in
stl_list.h:194:no type named 'allocator_type' in
stl_list.h:197:no type named 'allocator_type' in
stl_list.h:257:no type named 'allocator_type' in
stl_list.h:309:no type named 'allocator_type' in
stl_list.h:356:no type named 'allocator_type' in
stl_list.h:360:no type named 'allocator_type' in
stl_list.h:525:no type named 'allocator_type' in
stl_list.h:538:no type named 'allocator_type' in
------------------------------------------------------------------------------------------------

These are the exact errors and i have mentioned as it is.


Except for the errors of the typedefs.h file all other errors are from the STL Library files like the stl_list.h and stl_alloc.h file, which u can get from the STL Library.

The exact line which is giving error in typedefs.h file (ln 9) is :

typedef persistentlist<CCktElem*>::iterator LIST_ITERATOR;

In this file (typedefs.h) the file persistentlist.h is included which has some of the contents:


template< class _Ty, class _A = AllocatorInterface< _Ty > > class persistentlist
ublic CPersists,public list< _Ty , _A >{


public :

persistentlist() {
}

If u match it closely with the STL Library u will find its contents similar to list file.But i cant help it out since it was similar to the list file on Windows and i am trying to make the entire code compatible with list file of the Linux.

Just to add more information : This file (persistentlist.h) has the allocator.h file included in it.

Some of the contents of this file are:


template <class DataType>
class AllocatorInterface ublic CPersists{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef DataType * pointer;
typedef const DataType * const_pointer;
typedef DataType & reference;
typedef const DataType & const_reference;
typedef DataType value_type;


So, i have added enough information from my side to give clear picture.

Plz give me direction to sort the issue.

Thanks ! - vipinsharma
 
Old 05-21-2004, 10:42 AM   #4
bluie
LQ Newbie
 
Registered: May 2004
Location: Europe
Distribution: Mutable
Posts: 10

Rep: Reputation: 0
Hi vipinsharma!
I suggest we try to make a minimal example that isolates the problem.
Quote:
stl_alloc.h:844:No class template named 'rebind' in
I already have a similar compiler-error as the error above.
To achieve a minimal example some questions need to be answered.
Maybe the answers are just the beginning.
Quote:
The exact line which is giving error in typedefs.h file (ln 9) is :
typedef persistentlist<CCktElem*>::iterator LIST_ITERATOR;
What is CCktElem? Can we replace it by int for simplicity?
Quote:
template< class _Ty, class _A = AllocatorInterface< _Ty > >
class persistentlist ublic CPersists,public list< _Ty , _A >{
What exactly is CPersists? This is relevant, because
AllocatorInterface inherits from it.
Quote:
template <class DataType>
class AllocatorInterface ublic CPersists{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef DataType * pointer;
typedef const DataType * const_pointer;
typedef DataType & reference;
typedef const DataType & const_reference;
typedef DataType value_type;
Does AllocatorInterface end that way? Can't find the '}'? What is
the complete definition of AllocatorInterface?
Quote:
So, i have added enough information from my side to give clear picture.
I don't think so.

Up to now I have the following code. Maybe this can be a reasonable
start.
Code:
// file persistentlist.h

#include <list>

template <class DataType>
class AllocatorInterface : public CPersists {
public:
  typedef size_t size_type;
  typedef ptrdiff_t difference_type;
  typedef DataType * pointer;
  typedef const DataType * const_pointer;
  typedef DataType & reference;
  typedef const DataType & const_reference;
  typedef DataType value_type;
};

template<class _Ty, class _A = AllocatorInterface<_Ty> >
class persistentlist: public std::list<_Ty, _A>
{
public:
  int
  foo() { return 42; }
};
Code:
// file main.cpp

#include "persistentlist.h"

typedef persistentlist<int*>::iterator LIST_ITERATOR; 

int main()
{
  persistentlist<int> aList;
  int bar = aList.foo();
  
  return 0;
}
The compilation looks like this.
Code:
g++ -c -o main.o /home/xy/prog/c++/usinglist/main.cpp
In file included from /home/xy/prog/c++/usinglist/main.cpp:4:
/home/xy/prog/c++/usinglist/persistentlist.h:6: error: expected class-name before '{' token
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0/bits/stl_list.h: In instantiation of `std::_List_base<int*, AllocatorInterface<int*> >':
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0/bits/stl_list.h:388:   instantiated from `std::list<int*, AllocatorInterface<int*> >'
/home/xy/prog/c++/usinglist/persistentlist.h:19:   instantiated from `persistentlist<int*, AllocatorInterface<int*> >'
/home/xy/prog/c++/usinglist/main.cpp:6:   instantiated from here
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0/bits/stl_list.h:295: error: no class template named `rebind' in `class AllocatorInterface<int*>'
And you can see the `rebind' in the last line.

Hope we can solve that thing.
Bye, bluie
 
Old 05-22-2004, 01:42 AM   #5
vipinsharma
LQ Newbie
 
Registered: May 2004
Posts: 9

Original Poster
Rep: Reputation: 0
Hi bluie.

U have understood the problem very well - as far as the information is concern Ya i admit that the picture is not yet clear But its becoz the dependecies in the files are so long that its not possible to list all.

IF i will list CPersist then again another class in inherited and this way its a long chain.

Also u have targetted the problem right. These are the exact errors i am getting which u have got. it asks for the rebind file defintion which is thr in file stl_alloc.h

How should this be sorted ?
// File allocator.h

using namespace std;

#include<CPersists.h>


template <class DataType>
class AllocatorInterface ublic CPersists{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef DataType * pointer;
typedef const DataType * const_pointer;
typedef DataType & reference;
typedef const DataType & const_reference;
typedef DataType value_type;



~AllocatorInterface(){} ;

//contents are long...some inline functions are defined in it.

}


//File Persistentlist.h

#include<list>
#include<allocator.h>
#include<CPersists.h>

using namespace std;

template< class _Ty, class _A = AllocatorInterface< _Ty > > class persistentlist
ublic CPersists,public list< _Ty , _A >{


public :

persistentlist() {
}

// contents are again long....some inline functions are defined in it.
}


//File typedefs.h


#ifndef TypeDefs_h
#define TypeDefs_h 1
#include<CCktElem.h>
#include<persistentlist.h>
#include<persistentvector.h>

typedef persistentlist<CCktElem*>::iterator LIST_ITERATOR;

//some more typedefs included in the file using persistentvector.h

#endif


Actually these seperate header files are used in some other file which is included in a .cpp file. So while compiling the same errors are obtained.

bluie - can u plz tell me how to sort this problem. I am trying hard since last 3 days but could not catch the nerves !

Thanks
Ashish
 
Old 05-24-2004, 07:08 AM   #6
sheenak
LQ Newbie
 
Registered: Apr 2004
Posts: 23

Rep: Reputation: 15
Hi Bluie,

No response since long - i am still waiting ur response.

Should i consider it some drawback of compiler or i am missing something.

I have full faith in Compiler so i think i am missing something.

Guide me !

Ashish
 
Old 05-26-2004, 04:33 AM   #7
sheenak
LQ Newbie
 
Registered: Apr 2004
Posts: 23

Rep: Reputation: 15
Hi,

I have finally solved the problem.

the statement :

typedef persistentlist<CCktElem*>::iterator LIST_ITERATOR;

had an argument missing because it is considered as a default parameter (since it is assigned a Default value during the double argument template Defintion). But in Linux we need to mention that also.

typedef persistentlist<CCktElem*, allocator<CCktElem*>>::iterator LIST_ITERATOR;


That solves the problem.
 
Old 05-26-2004, 04:35 AM   #8
sheenak
LQ Newbie
 
Registered: Apr 2004
Posts: 23

Rep: Reputation: 15
Just to mention sheenak, vipinsharma are my frenz.

Ashish
 
Old 05-29-2004, 12:53 PM   #9
bluie
LQ Newbie
 
Registered: May 2004
Location: Europe
Distribution: Mutable
Posts: 10

Rep: Reputation: 0
Hi Ashish, sheenak, vipinsharma!
Good to hear that you solved the problem.
Sorry for my absence but I had some other stuff to do.
I hoped many others would help.

Bye, bluie
 
Old 06-01-2004, 03:46 AM   #10
vipinsharma
LQ Newbie
 
Registered: May 2004
Posts: 9

Original Poster
Rep: Reputation: 0
Hi Guys,

I am really not sure whether the applied method has solved my problem or not. Though to some extent i feel that this was the problem of the syntha



Quote:
--------------------------------------------------------------------------------
Hi,

I have finally solved the problem.

the statement :

typedef persistentlist<CCktElem*>::iterator LIST_ITERATOR;

had an argument missing because it is considered as a default parameter (since it is assigned a Default value during the double argument template Defintion). But in Linux we need to mention that also.

typedef persistentlist<CCktElem*, allocator<CCktElem*>>::iterator LIST_ITERATOR;


That solves the problem.


--------------------------------------------------------------------------------


I am not sure whether this has solved the problem or not. I am no more getting any kind of parse errors but still facing problem at other places where this VECTOR_ITERATOR user defined data type has been used. Though LIST_ITERATOR is working absolutely fine.

To address the problem in better manner :

In the source code :


//Contents of File - persistentvector.h
------------------------------------------------------
#include "allocator.h"


template <class _Tp, class _Alloc = AllocatorInterface<_Tp> > class persistentvector
: public CPersists,public vector<_Tp ,_Alloc>

{

typedef persistentvector< _Tp, _Alloc > _Mypersistent;

public :
typedef _Tp value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef size_t size_type;
typedef pointer _Tptr;
typedef __gnu_cxx:: __normal_iterator< pointer,_Mypersistent > iterator;
typedef __gnu_cxx:: __normal_iterator< const_pointer,_Mypersistent > const_iterator;
typedef iterator _It;

Also thr are some of the functions like insert defined in this file.....


//Contents of File - typedefs.h
------------------------------------------------------
#include "persistentvector.h"

typedef persistentlist<CCktElem*,allocator<CCktElem*> >::iterator LIST_ITERATOR;

typedef persistentvector<CCktElem*, allocator<CCktElem*> >::iterator VECTOR_ITERATOR;

typedef persistentvector <CCktElem*,allocator<CCktElem*> > CKTELEM_DARRAY;

typedef persistentlist<CCktElem*, allocator<CCktElem*> > CKTELEM_LIST;

typedef persistentlist<CCktElem*,allocator<CCktElem*> >* PTR_CKTELEM_LIST;

typedef persistentvector<CCktElem*,allocator<CCktElem*> >* PTR_CKTELEM_DARRAY;
--------------------------------------------------------------------------


//Contents of File - ClogicElem.h
-------------------------------------------
#include "typedefs.h"

#include<CCktElem.h>


class CLogicElem : public CCktElem{
protected:

CLogicElem(unsigned int id): CCktElem(id)
{
#ifdef _DEBUG
m_pDBGCktElemName = NULL;
m_pDBGSourceList = NULL;
m_pDBGSinkList = NULL;
m_bDBGVisitedFlg = false;
#endif
}


LIST_ITERATOR Begin(PTR_CKTELEM_LIST pListPtr);

LIST_ITERATOR End(PTR_CKTELEM_LIST pListPtr);

VECTOR_ITERATOR Begin(PTR_CKTELEM_DARRAY pVectorPtr);

VECTOR_ITERATOR End(PTR_CKTELEM_DARRAY pVectorPtr);


};

inline LIST_ITERATOR CLogicElem::Begin(PTR_CKTELEM_LIST pListPtr)
{
return pListPtr->begin();
}

inline LIST_ITERATOR CLogicElem::End(PTR_CKTELEM_LIST pListPtr)
{
return pListPtr->end();
}

inline VECTOR_ITERATOR CLogicElem::Begin(PTR_CKTELEM_DARRAY pVectorPtr)
{
return pVectorPtr->begin();
}

inline VECTOR_ITERATOR CLogicElem::End(PTR_CKTELEM_DARRAY pVectorPtr)
{
return pVectorPtr->end();
}

The errors are obtained in the above function having return type VECTOR_ITERATOR. These begin and end functions are giving following compile time errors:


Errors:
conversion from `_gnu_cxx::__normal_iterator<CCktElem**, std::vector<CCktElem*,
std::allocator<CCktElem*> > >' to non-scalar type `
__gnu_cxx::__normal_iterator<CCktElem**, persistentvector<CCktElem*,
std::allocator<CCktElem*> > >' requested

In member function 'VECTOR_ITERATOR CLogicElem::End(persistentvector<CCktElem*,
std::allocator<CCktElem*> >*)':

conversion from `__gnu_cxx::__normal_iterator<CCktElem**, std::vector<CCktElem*,
std::allocator<CCktElem*> > >' to non-scalar type `VECTOR_ITERATOR'
requested


Though the similar functions having the return type LIST_ITERATOR are working fine.

Its just very difficult to track the exact problem.


Is it because of the definition of the VECTOR_ITERATOR that i am facing some problem or is there some kind of error in the definition of the term 'iterator' which is under the class persistentvector defined.

Plz guide me guys
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NSS will not compile due to nspr4 library error juliensteel Linux - General 0 01-21-2005 08:40 AM
problems using the SGI STL library nigham Programming 2 10-08-2004 10:33 PM
GCC + STL Compile Problem Hairein Programming 6 09-23-2004 08:43 AM
gcc STL include problem finidi Programming 3 01-14-2003 06:55 AM
C++ STL problem jaycee999 Programming 5 05-31-2002 03:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration