MyClass<2> a(vector<float>());
This is not a variable declaration. This is a declaration of a function named a , which returns a MyClass<2> object and takes as argument "a pointer to a function that takes no arguments and returns vector<float> ". Mixing? Yes. This is what is called the "most unpleasant analysis."
You need extra parentheses:
MyClass<2> a((vector<float>())); ^ ^
Or you can use copy initialization:
MyClass<2> a = MyClass<2>(vector<float>());
Or, since your constructor is not explicit , you can use:
MyClass<2> a = vector<float>();
(Although, if you do not want the vector<float> objects to be implicitly convertible to MyClass<N> objects, you probably want to make this constructor explicit .)
A good compiler should warn you about this. Visual C ++ warns:
warning C4930: ' MyClass<x> a(std::vector<_Ty> (__cdecl *)(void)) ': the prototyped function was not called (was the variable defined?)
Klang warns:
warning: parentheses were ambiguous as a function declarator
MyClass<2> a(vector<float>()); ^~~~~~~~~~~~~~~~~
James McNellis
source share