Discussion: template and typedef
Afficher un message
Vieux 21/02/2008, 17h07   #4
Kira Yamato
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: template and typedef

On 2008-02-21 10:59:16 -0500, Kira Yamato <kirakun@earthlink.net> said:

> On 2008-02-21 05:05:38 -0500, Berardino la Torre
> <berardino.latorre@hotmail.com> said:
>
>> Hi All,
>>
>> is it possible to do something like this ? :
>>
>> template <typename Base>
>> class Object : public Base::Interface {
>> };

>
> g++ seems to complain that you cannot inherit from an incomplete type Base.
>
> This is interesting. Just when you think you've figured out how
> template works, here comes another example showing you how much you
> don't know.


Well I suppose it makes sense that this should be an error. It's
basically a circular definition that could lead to infinite regress.
For example,

template<class T>
class A : public T {};

class B : public A<B>
{
int x;
};

But this code expands to

class B : public B
{
int x;
};

Hence the infinite regress.

>
>>
>> class IA{
>> virtual void print()=0;
>> };
>>
>> class A : public Object<A>{
>> public:
>> typedef IA A::Interface;
>> void print(){
>> }
>> };

>
> Seems like your goal is to have class A inherit from A::Interface. So,
> why not consider the following:
>
> class IA {};
>
> class A : public IA
> {
> public:
> typedef IA Interface;
> };
>
>>
>>
>> int main(){
>>
>> return 0;
>> }


--

// kira

  Réponse avec citation
 
Page generated in 0,04784 seconds with 9 queries