Trouble initializing a templated class

Vlad Levenfeld via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 5 10:19:29 PDT 2014


On Saturday, 5 July 2014 at 17:17:03 UTC, quakkels wrote:
>> try SomeClass (T): BaseClass
>
> Not sure which line you want me to change. I don't want 
> SomeClass to inherit from BaseClass. Rather, I want T to be 
> restricted to classes that inherit from BaseClass.
>
> When I change `class SomeClass(T : BaseClass)` to `class 
> SomeClass(T) : BaseClass` I still get the "class 
> templateExp.SomeClass(T) is used as a type" error.

ah, sorry, I misunderstood. It looks like you need to change the 
lin

auto sc = new SomeClass ();

to

auto sc = new SomeClass!BaseClass ();

The compiler complains because SomeClass is a template when you 
call SomeClass() without !() template parameters. It only becomes 
a type once instantiated with parameters.


More information about the Digitalmars-d-learn mailing list