std::list member in class? - vc6 problem?

G

Gernot Frisch

class A
{
public:
std::list<A> m_a;
};

yields errorC2079: '_Value' uses undefined class 'A'

using std::vector will work...

How can I get it working with VC6?
 
E

Eric Lilja

Gernot Frisch said:
class A
{
public:
std::list<A> m_a;
};

yields errorC2079: '_Value' uses undefined class 'A'

using std::vector will work...

How can I get it working with VC6?

Storing pointers maybe?
 
G

Gernot Frisch

Eric Lilja said:
Storing pointers maybe?


// in .h:

class A
{
class DATA;
DATA* pData;
}

// in .cpp
class A::DATA
{
std::list<A> m_A;
};

worked for me - but it's not nice and I start disliking VC6 more and
more.
 
E

Eric Lilja

Gernot Frisch said:
// in .h:

class A
{
class DATA;
DATA* pData;
}

// in .cpp
class A::DATA
{
std::list<A> m_A;
};

worked for me - but it's not nice and I start disliking VC6 more and more.

Off-topic:
Well, it is seven (or is it eight?) years old now. I used it for many years,
but now I use MSVC++ 7.1 or GCC 3.4.3. It's much easier to port
standards-conforming C++ code between the two than it was when I was using
MSVC++ 6.0 (and an older version of gcc). If you have to work with such an
old tool due to a misinformed decision by a non-technical boss, you have my
pity.

/ Eric
 
M

Marek Vondrak

Gernot Frisch said:
Off-topic:
Well, it is seven (or is it eight?) years old now. I used it for many years,
but now I use MSVC++ 7.1 or GCC 3.4.3. It's much easier to port
standards-conforming C++ code between the two than it was when I was using
MSVC++ 6.0 (and an older version of gcc). If you have to work with such an
old tool due to a misinformed decision by a non-technical boss, you have my
pity.

Well. I do not want to advocate for MSVC but this has entirely nothing to do
with the compiler but the library (std::list) implementation. I do not know
if standard requires the above code to work and if yes, the library is to
blame.

MV
 
P

Peter Koch Larsen

Marek Vondrak said:
Well. I do not want to advocate for MSVC but this has entirely nothing to
do
with the compiler but the library (std::list) implementation. I do not
know
if standard requires the above code to work and if yes, the library is to
blame.

The library is naturally restricted by the compiler so this is not
black-and-white. Actually I believe that the VC6.0 STL implementation is
reasonable, considering the limitations of the compiler.
/Peter
 
O

Old Wolf

Gernot said:
class A
{
public:
std::list<A> m_a;

The template parameter must be a complete type at the point of
instantiation.

Some other compilers have similar problems with your code; for
};

yields errorC2079: '_Value' uses undefined class 'A'

using std::vector will work...

Not guaranteed by the standard.
How can I get it working with VC6?

This seems to work on my system, although I don't know if it's
standard:

template<int n> class A_
{
public:
std::list<A_> m_a;
};

typedef A_<0> A;
 
M

msalters

Old said:
The template parameter must be a complete type at the point of
instantiation.
This seems to work on my system, although I don't know if it's
standard:

template<int n> class A_
{
public:
std::list<A_> m_a;
};

typedef A_<0> A;

Definitely illegal. The argument to std::list<> must be a type. You
pass a template.

The best solution, which also reduces the number of headers included
was already mentioned. Use a pimpl idiom, and move the list to the
..cpp file. Another solution could be to store boost::ref<A>

HTH,
Michiel Salters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top