|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-05-30 06:48:39
From: "John Max Skaller" <skaller_at_[hidden]>
> > > But the example is a special case: just consider:
> > >
> > > template<class T1, class T2>
> > > struct X {
> > > smart_ptr<X<T2,T1> > ptr;
> > > };
> > >
> > > to see that it isn't always possible to forward declare things.
> >
> > What's the problem there?
>
> The problem is that there is NO ordering
> of template instances for which lookup in 'expanded'
> classes can work:
>
> struct X<A,B> { smart_ptr<X<B,A> > ptr; };
An interesting debate. This:
#include <boost/smart_ptr.hpp>
using boost::shared_ptr;
template<class T1, class T2> struct X
{
shared_ptr< X<T2,T1> > ptr;
};
int main()
{
X<int, long> x;
return 0;
}
compiles with g++ 2.95.2. I don't know about .3.
If we get back to your original example:
class X;
class Y { shared_ptr<X> p; };
I believe that a compiler is within its rights to reject the code. Members
of class templates should not be instantiated unless used; however, Y is not
itself a template, so the compiler _may_ legitimately generate Y::~Y() at
the end of Y's definition, which in turn uses
shared_ptr<X>::~shared_ptr<X>().
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk