?
=?ISO-8859-1?Q?S=F8ren?= Holstebroe
Hi there,
I'm having a struggle with GNU g++ (3.3.5) and inheritance of typedefs in
STL containers.
I'm trying to port some old code I wrote with MS Visual C++ and it looks
like there is a discrepancy in the STL implementation or at least
interpretation of the standard (I trust g++ most on the latter).
To the case:
While this compiles fine:
-------------------
class B {
public:
typedef int foo;
};
class C : public B {
public:
void bar() {
foo a;
}
};
-------------
This doesn't work:
------------------
template <typename T, template <typename ELEM> class CONT = std::vector>
class pointainer : public CONT<T *>
{
public:
void foo() {
CONT<T *>::iterator it;
}
};
------------
tpltest.cc: In member function `void pointainer<T, CONT>::foo()':
tpltest.cc:9: error: parse error before `;' token
The vector iterator is defined in include/g++-v3/bits/stl_vector.h like
this:
typedef __gnu_cxx::__normal_iterator<pointer, vector_type> iterator;
Another thing is that I'm not sure that I'm on the right track when I
try to overwrite some functionalities of STL containers by inheritance.
I have been using a pointainer by Yonat Sharon in visual c++ for a long time
that was implemented in a similar way, but this pointainer doesn't compile
with g++.
The purpose of the pointainer is to automatically call the dtor of it's
objects when they are removed from the pointainer (or when the pointainer
is destructed). Yonat implemented that by overwriting many of the key
methods of the stl container. Since these methods are non-virtual, it would
give problems if the pointainer is used in a mother STL class context.
Currently I only see the solution of using composition instead of
inheritance which should clean any semantic problems, but will throw out my
free lunch. However I'm still curious why g++ wouldn't accept the stl
iterator usage.
I'm having a struggle with GNU g++ (3.3.5) and inheritance of typedefs in
STL containers.
I'm trying to port some old code I wrote with MS Visual C++ and it looks
like there is a discrepancy in the STL implementation or at least
interpretation of the standard (I trust g++ most on the latter).
To the case:
While this compiles fine:
-------------------
class B {
public:
typedef int foo;
};
class C : public B {
public:
void bar() {
foo a;
}
};
-------------
This doesn't work:
------------------
template <typename T, template <typename ELEM> class CONT = std::vector>
class pointainer : public CONT<T *>
{
public:
void foo() {
CONT<T *>::iterator it;
}
};
------------
tpltest.cc: In member function `void pointainer<T, CONT>::foo()':
tpltest.cc:9: error: parse error before `;' token
The vector iterator is defined in include/g++-v3/bits/stl_vector.h like
this:
typedef __gnu_cxx::__normal_iterator<pointer, vector_type> iterator;
Another thing is that I'm not sure that I'm on the right track when I
try to overwrite some functionalities of STL containers by inheritance.
I have been using a pointainer by Yonat Sharon in visual c++ for a long time
that was implemented in a similar way, but this pointainer doesn't compile
with g++.
The purpose of the pointainer is to automatically call the dtor of it's
objects when they are removed from the pointainer (or when the pointainer
is destructed). Yonat implemented that by overwriting many of the key
methods of the stl container. Since these methods are non-virtual, it would
give problems if the pointainer is used in a mother STL class context.
Currently I only see the solution of using composition instead of
inheritance which should clean any semantic problems, but will throw out my
free lunch. However I'm still curious why g++ wouldn't accept the stl
iterator usage.