Ensuring template argument is descendant of class

Ross Hays test at gmail.com
Thu Dec 12 13:51:12 PST 2013


I am trying to see what I can make in the way of a game engine in 
D, and am currently trying to write a basic asset manager.

I have a base Asset class that all asset types are going to 
inherit; one such example of this is Texture. Now I am using the 
following code on the loadAsset method in the file manager...

     T loadAsset(T)(in string filename)
         if (cast(Asset)T)
     {...

Making a call such as...

     auto tex = loadAsset!Texture("/test.png")

...results in the following error at compile time...

     source\engine\assets.d(28): Error: Cannot interpret Texture 
at compile time

I am not sure what the best way to do something like this would 
be. I could always just take the template argument, and return an 
Asset object, but then the calling code would need to cast the 
object returned and I am trying to avoid that if possible.

Thanks!

Ross


More information about the Digitalmars-d-learn mailing list