digitalmars.D.learn - Templated class requires values even though having default value
- tcak (18/18) May 09 2021 public class OpenCLKernel(size_t dim = 1) if( (dim >= 1) && (dim
- Adam D. Ruppe (9/11) May 09 2021 It doesn't, but it does require you to instantiate the template.
public class OpenCLKernel(size_t dim = 1) if( (dim >= 1) && (dim <= 3) ) { public this( OpenCLProgram program, in string kernelName ) { // ... } } I have a class definition as above. When I want to create an instance as below, OpenCLKernel k = new OpenCLKernel( program, "kernelName" ); compiler tells me, /test2.d(168): Error: template class `OpenCLKernel(ulong dim = 1) if (dim >= 1 && (dim <= 3))` is used as a type without instantiation; to instantiate it use `OpenCLKernel!(arguments)` The "dim" template parameter has a default value of 1 already. Why does it still force me to give a value? (DMD64 D Compiler v2.096.0)
May 09 2021
On Sunday, 9 May 2021 at 10:53:49 UTC, tcak wrote:The "dim" template parameter has a default value of 1 already. Why does it still force me to give a value?It doesn't, but it does require you to instantiate the template. You can do `OpenClKernel!()` to use the default value. But without that ! instantation, you're just referring to a template name, not a class. You might want to try something like class GenericOpenClKernel(....) {} alias OpenClKernel = GenericOpenClKernel!(); depending on the intended uses.
May 09 2021