another c++ q (with specialization and inheritance )

another c++ q (with specialization and inheritance )

Erez D erez0001 at gmail.com
Tue Apr 28 11:35:10 IDT 2009


On Tue, Apr 28, 2009 at 11:08 AM, Shachar Shemesh <shachar at shemesh.biz>wrote:

>  Erez D wrote:
>
>         c2<int> gen_c2(int a)
>         {
>                 c2<int> ret(a);
>                 return ret;
>         }
>
> It would seem to me that this line instantiates c2<int>, so that
>
> template <> class c2<int> : public c1<int>
> {
> public:
>         c2(int &a):c1(a) {};
> };
>
>  is an attempt to specialized a class that has already been instantiated
> from the generic template. The compiler has no way to go back and change the
> storage size for c2<int>, which it already needed to know when compiling the
> lines above.
>

I can't write c2 first as it is derived out of c1
I can't write c1 first as it has a function that returns c2
if i use forward declaration (like i did), i get "specialization after
instanciation"


> Try to have gen_c2 return a pointer to c2<int>. That may resolve the
> problem.
>
no, it doesnt.

i am sure that there is a solution to this.
but i don't know what it is.

thanks,
erez.

>
> Shachar
>
> --
> Shachar Shemesh
> Lingnu Open Source Consulting Ltd.http://www.lingnu.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20090428/e0aef622/attachment.html>


More information about the Linux-il mailing list