This is the mail archive of the gcc@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: gcc 2.95.1 can't compile correnct code (SUN's CC can)


> > I am wondering, why gcc-2.95.1 does not compile the appended piece of code 
> > (whereas SUN's C++ Compiler (5.0) does compile it). Any hints how to compile 
> > this code with GNU g++ would be very welcome.
> 
> You cannot compile this code with g++, since it is not valid C++. If
> SUN CC accepts it (without diagnostics), I think this is a bug in that
> compiler.
> 
> > class b;
> > 
> > class a{
> > public:
> >   a(){}
> >   list<b> c;
> > };
> 
> Here, b is an incomplete type. To instantiate the list template, you
> need a complete type.
> 
> I'm not sure what you are trying to achieve; here is a number of
> alternatives:
> 
> a) you could have lists of pointers to a and b. This is ok, since a
>    pointer type is a complete type.
> 
> class a{
> public:
>   a(){}
>   list<b*> c;
> };
> 
> b) you could have pointers to lists inside the classes. This is ok
>    since defining a pointer-to-template does not require instantiation
>    of the template.
> 
> class a{
> public:
>   a(){}
>   list<b> *c;
> };
> 
> In either case, you'll probably have to define a copy constructor and
> a destructor.
> 

Thanks for the clarification. Is this a limitation of C++ template concept:

If I would implement the list myself (non-templete, something like list_b), I 
wouldn't need a complete type of b, because my list implementation would 
contain only pointers to b, because it has no instance of b when the 
constructor is called.

I might be interesting, that Maxi, who found the problem, told me, that it 
works with gcc 2.8.1.

Thanks.


--Rainer.



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