Template interface and class

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed May 30 14:20:53 PDT 2007


"gerleim" <elf_qt at _deletethisifyouarenotaspammer_yahoo.com> wrote in message 
news:f3klfg$nrq$1 at digitalmars.com...
>
> Thanks for the answer, but I'm not fully convinced. A better example:
>
> class C(T) : I!(T)
> { }
>
> public interface I(T)
> {
> void Foo();
> }
>
> Aside from the template it is sure that C misses implementation.
> That is also sure from my first example. That's not decided what type is 
> T, but a method must be present with the name Foo.

Until you instantiate the template, no class exists.  Period.  No class 
means no way to check if it's right.  The compiler does not do semantic 
analysis on template contents until they're instantiated, because there is 
absolutely no way to know, without knowing the template parameters, whether 
the code inside is valid or not.  Because just like with templated 
functions, templated classes are syntactic sugar.  Your class declaration is 
really saying:

template C(T)
{
    class C : I!(T) { }
}

Now it's obvious that there is no class at top-level. 




More information about the Digitalmars-d-learn mailing list