Combining variadic functions with class templates

Sebastian Schuberth sschuberth at gmail.com
Thu Sep 30 10:53:17 PDT 2010


Hi,

I'm all new to D (coming from C++), and currently playing around with 
the language. I'm using DMD 2.049 and was expecting this to compile:

struct Vector(alias N,T)
{
     Vector(T[N] v ...) {
         data=v;
     }

     T data[N];
};

alias Vector!(3,float) Vec3f;

void main()
{
     Vec3f v(1,1,1);
}

But instead I get these errors:

Building Release\ConsoleApp1.exe...
main.d(3): found 'v' when expecting ')'
main.d(3): semicolon expected, not '...'
main.d(3): Declaration expected, not '...'
main.d(8): unrecognized declaration
Building Release\ConsoleApp1.exe failed!

What's wrong with the above code? Can member functions / constructors 
not be variadic? Is is not allowed to use template argument N in static 
array variadic function arguments?

Thanks in advance.

-- 
Sebastian Schuberth


More information about the Digitalmars-d-learn mailing list