Topic: different implementations of recursive type defs in templates


Author: Jan-Peter de Ruiter <Jan-Peter.deRuiter@mpi.nl>
Date: 1997/03/25
Raw View
Hello,

We've noticed that the following fragment, representing a simple list
class, is accepted by some compilers (e.g. CodeWarrior 10) but not by
others (gcc 2.7.2, Borland 4.x). The compilers that do not accept this
complain that the type X is unknown in the line indicated by <---.


template <class X> class Link
{
    X x; // <--- 'incomplete type' error generated by some compilers
    Link<X>* next;
};

template <class X> class List
{
    Link<X>* first;
    Link<X>* last;
};

class T
{
  public:

    int x;
    List<T> children;
};

void main()
{
    T t;

    t.x = 1;
}


Our question is: what does the current standard prescribe here?

If one expands the templates in the example above by hand and then
compiles it, there seems to be no problem, so how can the presence of a
template change that?

regards,

Jan

----
Jan Peter de Ruiter
Max Planck Institute for Psycholinguistics
Nijmegen, the Netherlands
janpeter@mpi.nl
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]