Kai-Uwe Bux
12/8/2008 11:19:00 PM
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