Topic: recursive dependency in heritence supported???


Author: "Andrew Robb" <ajrobb@bigfoot com@uunet.uu.net>
Date: Fri, 5 Oct 2001 17:52:36 GMT
Raw View
This template class does not contain DerivedType, it just uses a reference
to it.
It is legal to define a reference or pointer to a partially defined type:

struct A {
  struct A * next;
};

> "..The class-name in a base-specifier shall not be an incompletely
> defined class..." (class.derived)
>
> Could you please direct me to a place in the Standard allowing such a
> code to compile?


---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: vm_usenet@yahoo.com (vm_usenet)
Date: Thu, 27 Sep 2001 19:26:33 GMT
Raw View
In his article "Curiously Recurring Template Patterns", James Coplien
refers to a code written in a menuscript by John Burton and Lee
Nackman, which looks essentially like this:

template <class DerivedType>
class EquivalentCategory {
  friend bool operator=(const DerivedType & a, const DerivedType & b)
  {
    return a.equalsTo(b);
  }
  ...
};

class Apple : public EquivalentCategory<Apple> {
...
};

James goes even further and says that he went to the authors of the
code and told them that this code is illegal in C++ because the
compiler can never reduce the cyclic dependency between the base and
derived classes. Burton and Nackman redirected him to a verse in the
Standard that claims that it is legal.

I hope you would forgive me from my ignorance, but I couldn't find
such a verse in the Standard... The only thing I could find is a verse
claiming that:
"..The class-name in a base-specifier shall not be an incompletely
defined class..." (class.derived)

Could you please direct me to a place in the Standard allowing such a
code to compile?

thanx and again, sorry for my ignorance,

vm

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Carl Daniel" <carl@pixami.com>
Date: Thu, 27 Sep 2001 20:56:47 GMT
Raw View
"vm_usenet" <vm_usenet@yahoo.com> wrote in message
news:c09aca51.0109271125.44345a7@posting.google.com...
> Could you please direct me to a place in the Standard allowing such a
> code to compile?
>

I can't quote chapter & verse, since my copy of the standard is at home, but
I'm sure this is legal.  The key is in how Apple is used.  Note that it does
not derive from itself, it merely derives from a template which references
itself.  If (and only if) the template can be instantiated when Apple itself
is (or would've been) an incomplete type, then the inheritance is legal.

This is a common idiom.  Common enough that (IMO) if the Standard
inadvertantly prevents it, then it's a defect in the standard.

-cd



---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]