[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Using class type in class?

mlt

12/8/2008 10:22:00 PM

I have some code that looks like this:

template<typename math>
class FirstClass {

public:
typedef math math_types;
typedef FirstClass<math_types> types;
...
typedef SecondClass<types> second_type;
...

}


How can a class typedef itself (FirstClass) and be used as a template
parameter for another type (SecondClass)? Don't I need to define
FirstClass before I can use it as a type parameter for SecondClass?

1 Answer

Kai-Uwe Bux

12/8/2008 11:19:00 PM

0

mlt wrote:

> I have some code that looks like this:
>
> template<typename math>
> class FirstClass {
>
> public:
> typedef math math_types;
> typedef FirstClass<math_types> types;
> ...
> typedef SecondClass<types> second_type;
> ...
>
> }
>
>
> How can a class typedef itself (FirstClass) and be used as a template
> parameter for another type (SecondClass)? Don't I need to define
> FirstClass before I can use it as a type parameter for SecondClass?

In principle, you don't need to define a type before it can be used as a
template parameter: in other words, you can use incomplete types as
template parameters. In that case, however, the program has undefined
behavior if completing the type changes the semantics (and there might be
some more, technical restrictions). In any case, the compiler is not
required to issue a diagnostic.

Also, the templates from the standard library can only be instantiated from
complete types. Otherwise, you have undefined behavior.


Best

Kai-Uwe Bux