Discussion: template and typedef
Afficher un message
Vieux 21/02/2008, 20h57   #5
Jeff Schwab
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: template and typedef

Berardino la Torre wrote:
> Hi All,
>
> is it possible to do something like this ? :


[Summarized for brevity:]

template <typename Base>
struct Object: Base::Interface { };

struct IA { virtual void print() =0; };

struct A: Object<A> {
typedef IA A::Interface;
void print() { }
};


You're trying to derive a class (indirectly) from a type defined within
that class. I don't know of any direct way to do that. You can instead
move the type definition outside the class itself, e.g. into a traits class:

template<typename T>
struct Interface;

template <typename Base>
struct Object: Interface<Base>::Type { };

struct IA { virtual void print() =0; };

struct A;

template<>
struct Interface<A> {
typedef IA Type;
};

struct A: Object<A> {
void print() { }
};
  Réponse avec citation
 
Page generated in 0,04542 seconds with 9 queries