Use class template as a type

dm via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 28 06:13:36 PST 2016


> Thats because MyClass is a template class. Templates are note 
> types, instansiations of  templates can be types.
> e.g.
>
>     Myclass!float[] arr; // note this is not MyClass!(float[]);
>
> will work. As Rikki suggested using Object[] instead will allow 
> use to store classes of different types.

Maybe I must use some stub class or interface and override all 
methods...
But I so like D templates, as a result it's a small and easy to 
understand code.

Or actually it's maybe a XY problem. I'm trying to implement 
OpenGL material manager and for OpenGL uniforms I tried to write:
```
abstract class Uniform(T)
@property ...
@property ...
T _val;...
void method()...
...
class FloatUniform: Uniform!float
...
override void method()...

And in material class
class Material
...
Texture[] textures;
Uniform[] uniforms;
...
```
Maybe i'm totally wrong and better just use glUniformXXX... in my 
main app instead of
```
auto uniform = new SomeTypeUniform...
...
uniform.value = someValue;
```
?


More information about the Digitalmars-d-learn mailing list