Topic: Is a tree node as vector of trees valid?


Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/01/12
Raw View
comeau@panix.com (Greg Comeau) writes:

>"Gary Brown" <gbrown@thebrowns.ultranet.com> writes:
>>Is the following legal C++?
>>
>> class X {
>>     vector<X> ...;
>> };
>
>[...] you can certainly use a template argument with the same name
>as the class you are in, in this way.

You can _sometimes_ use a template argument with the same name
as the class you are in, but sometimes you can't.

For example, the following are legal (well-formed),

 template <class T> struct v1 { T* x; };
 template <class T> struct v2 { T y; };
 struct X {
  v1<X> a;
  v2<X> *b;
 };

but these are not:

 template <class T> struct v3 { T z; };
 template <class T> struct v4 { static const int size = sizeof(T); };
 struct Y {
  v3<Y> c;
  v4<Y> d;
 };

The implementation of the class template `vector' is not specified by
the DWP.  It might be like `v4' above.  Hence, it is unspecified whether

 class X {
     vector<X> ...;
 };

is well-formed or not; such constructs cannot be used in strictly
conforming programs.

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ 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                             ]





Author: "Gary Brown" <gbrown@thebrowns.ultranet.com>
Date: 1997/01/08
Raw View
Hi all,

Is the following legal C++?

 class X {
     vector<X> ...;
 };

Borland C++ 4.02 is happy with it.  Visual C++ 4.1 takes it only if the
vector declaration is placed after the constructor declarations.

It is meaningful but might be problematical for the compiler.  That VC++
works only with some fiddling makes me wonder if it is legal.

Thanks,
Gary



[ 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                             ]





Author: comeau@panix.com (Greg Comeau)
Date: 1997/01/10
Raw View
In article <01bbfd2b$67bad860$23f37392@thebrowns> "Gary Brown" <gbrown@thebrowns.ultranet.com> writes:
>Is the following legal C++?
>
> class X {
>     vector<X> ...;
> };
>
>Borland C++ 4.02 is happy with it.  Visual C++ 4.1 takes it only if the
>vector declaration is placed after the constructor declarations.
>
>It is meaningful but might be problematical for the compiler.  That VC++
>works only with some fiddling makes me wonder if it is legal.

I am not clear what you mean by that it required you to code ctor decls???

Anyway, you can certainly use a template argument with the same name
as the class you are in, in this way.  This tends to imply to me that
something is missing, hence I would like to ask that you show the code
that succeeds and the code that fails in order to clarify.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421


[ 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                             ]