Topic: class template base classes question


Author: "Gabor Greif" <gabor@no.netopia.com>
Date: 1999/02/19
Raw View
Hi.

I do not really understand the rationale behind the requirement that base
classes must be completely defined for class templates.

E.g. should this example compile?

struct A;

template <typename T>
struct Deriv : A
{

};

struct A { };

int main(void)
{
 Deriv<int> d;
}


My compiler tells me that A is incomplete in the Deriv template. What is
the exact reason that A has to be complete at template definition time (as
opposed to template instantiation time) ? I browsed the (draft) standard a
bit, but did not find a hint.

Thanks,

 Gabor




[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Alex Vinokur <alexander.vinokur@telrad.co.il>
Date: 1999/02/21
Raw View
In article <B2F309D3-4BFBB@192.168.1.8>,
  "Gabor Greif" <gabor@no.netopia.com> wrote:
>
> I do not really understand the rationale behind the requirement that base
> classes must be completely defined for class templates.
>
> E.g. should this example compile?
>
> struct A;
>
> template <typename T>
> struct Deriv : A
> {
>
> };
>
> struct A { };
>
> int main(void)
> {
>  Deriv<int> d;
> }
>
> My compiler tells me that A is incomplete in the Deriv template. What is
> the exact reason that A has to be complete at template definition time (as
> opposed to template instantiation time) ? I browsed the (draft) standard a
> bit, but did not find a hint.

This error message doesn't depend on the fact that Deriv is template struct.
Consider the following program :

------- Program#1 : BEGIN ---------
struct A;

struct Deriv : A
{

};

struct A { };

int main(void)
{
 Deriv d;
 return 0;
}
------- Program#1 : END ---------

The compilation result is the same :
 base class `A' has incomplete type

The reason is :
 struct A is declared before struct Deriv,
 but is not determinated.


The following program was compiled without error messages.

------- Program#2 : BEGIN ---------
struct A {};

struct Deriv : A
{

};

int main(void)
{
 Deriv d;
 return 0;
}
------- Program#1 : END ---------

 Alex

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]