S
Severin Ecker
hi,
alright, i was directed here from the comp.std.c++ group so I'll discuss
the issue here.
what i learned was that the following code sample results in undefined
behaviour so the outcome that i describe is perfectly legal.
now i would need some help/suggestion for how i can change the code to
defined correct c++ with as little work as possible since the code is
taken from a rather large project.
2 possibilities i can think of would be
a) change the template parameter of the vector to a pointer to Test
b) rearrange the code to move the typedefs after the full definition of
the type (I'm not sure if this even is possible in a lifetime due to
complex cyclic dependencies)
/// post from comp.std.c++
I'm currently working on/with a project and stumbled over a piece of
code which compiled just fine on VC05, VC08, gcc 4.1.1 but not on code
warrior. Then again if i use the stlport stl implementation the code
fails to compile on VC and gcc as well complaining because of the usage
of an undefined type (while compiling the 2nd typedef).
#include <vector>
struct Test;
typedef std::vector<Test> TestVec;
typedef TestVec::const_iterator TestVecIt;
So, actually I'm wondering whether this code complies to the c++
standard (on the one hand i thought templates are only evaluated when
they're instantiated, on the other hand the 2nd typedef needs to know
vector... hmm), but if not if there's any way i can get this to comply
(and compile) without the need to rewrite it using pointers to Test
(aka: std::vector<Test*>)
many thanks in advance!
cheers,
severin
alright, i was directed here from the comp.std.c++ group so I'll discuss
the issue here.
what i learned was that the following code sample results in undefined
behaviour so the outcome that i describe is perfectly legal.
now i would need some help/suggestion for how i can change the code to
defined correct c++ with as little work as possible since the code is
taken from a rather large project.
2 possibilities i can think of would be
a) change the template parameter of the vector to a pointer to Test
b) rearrange the code to move the typedefs after the full definition of
the type (I'm not sure if this even is possible in a lifetime due to
complex cyclic dependencies)
/// post from comp.std.c++
I'm currently working on/with a project and stumbled over a piece of
code which compiled just fine on VC05, VC08, gcc 4.1.1 but not on code
warrior. Then again if i use the stlport stl implementation the code
fails to compile on VC and gcc as well complaining because of the usage
of an undefined type (while compiling the 2nd typedef).
#include <vector>
struct Test;
typedef std::vector<Test> TestVec;
typedef TestVec::const_iterator TestVecIt;
So, actually I'm wondering whether this code complies to the c++
standard (on the one hand i thought templates are only evaluated when
they're instantiated, on the other hand the 2nd typedef needs to know
vector... hmm), but if not if there's any way i can get this to comply
(and compile) without the need to rewrite it using pointers to Test
(aka: std::vector<Test*>)
many thanks in advance!
cheers,
severin