🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2977

Re: Nested template class definitions

#2977
From: Fergus Henderson
Date: Mon, 01 Jan 1996 05:17
63 lines
2215 bytes
Robert DiFalco <difalco@primenet.com> writes:

>How do I define a nested class in a template?

You can define it either inline in the outer class declaration, or you
can just declare it in the outer class declaration and define it
later.  The latter method was allowed only relatively recently, and so
not all compilers support it yet.

>It seems to me that logic could offer this:
>
>   template <class Item>
>   class List_
>   {
>      public:
>         .
>         .
>         .
>         class Iterator;
>   };
>
>
>   template <class Item>
>   class List_<Item>::Iterator : public CollectionIterators_<Item>
>   {
>      .
>      .
>      .
>   };

Yep, that is exactly right.

>However, in Visual C++ 4.0, this produces the painfully ambiguous error
>message "error C2988: unrecognizable template declaration/definition".
>
>So, what gives? Is this an MSVC 4.0 problem, or am I use the incorrect
>syntax for defining a nested class outside of the outer classes scope?

It is an MSCV 4.0 problem.

As a work-around, try the following structure instead.

   template <class Item>
   class List_
   {
      public:
         .
         .
         .
         class Iterator {
		.
		.
		.
	};
   };

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <9600116.2625@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back
References: <4c525e$one@nnrp1.news.primenet.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Nested template class definitions
Message-ID: <9600116.2625@mulga.cs.mu.OZ.AU>
Originator: fjh@munta.cs.mu.OZ.AU
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <4c525e$one@nnrp1.news.primenet.com>
Date: Mon, 1 Jan 1996 05:17:06 GMT
Approved: fjh@cs.mu.oz.au
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMOduceEDnX0m9pzZAQFY7QF9EK70iYw0dM1WRzxowozcKIHOURPausyf
 Fz1flfvdQjfoh4kmmJejApKZrgNH9I71
 =Zgbg