This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++/3024: class inheritance of template arguments fail


> 
> template< class Base >
> class CComObject : public Base
> 
> Parameters
> 
> Base
> 
> Your class, derived from CComObjectRoot or CComObjectRootEx, as well as from 
> any other interfaces you want to support on the object.
> 
> CComObject implements IUnknown for a nonaggregated object. However, calls to 
> QueryInterface, AddRef, and Release are delegated to CComObjectRootEx.
> 
> - ----- END -----
> 
> When you create an ATL COM-object, you inherit from this class like:
> class ATL_NO_VTABLE MyClass : public CComObject<MyClass>
> {
> // ...
> };
> 

This code again does not compile in my VC++ with the same error message:

c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(2395) : error C2504: 'MyClass' : base class undefined
        C:\m\t1\t1.cpp(17) : see reference to class template instantiation 'ATL::CComObject<class MyClass>' being compiled

In C++, base class may not be an incomplete type. AFAIK, there is no extension
in VC++ that allows to circumvent this rule.

To elaborate:

template <typename T>
 class Y : public T
 {
 // T should be completely defined at this point.
 };
 
 class X : public Y<X>
 {
// Y<X> should be completely defined at this point.
// For it to be defined, X should be completely defined at this point, 
// but it isn't - you can't break out of this dependency loop.
 };

Suppose it was possible, and let class X have a data member, say, int a.
How many instances of a should be in class X ?

> At any rate, this is perfectly legal. This kind of stuff is quite neat, since 
> it allows you to very generic coding.  You can make boiler plate code go away 
> (joy! - In this case, the programmer is relieved of implementing the IUnknown 
> interface).

I beg to suppose that you refer to some other idiom here that does not involve 
inheritance from itself.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]