Can you tell me how to invoke template constructor explicitly (in initializer list)? for example:
struct T {
template<class> T();
};
struct U {
U() : t<void>() {} //does not work
T t;
};
thanks
Can you tell me how to invoke template constructor explicitly (in initializer list)? for example:
struct T {
template<class> T();
};
struct U {
U() : t<void>() {} //does not work
T t;
};
thanks
It's not possible. The Standard also has a note on this at
14.8.1/7
Explanation: This says: Template arguments are passed in angle brackets after a function template name, such as
std::make_pair<int, bool>
. And constructors don't have a name of their own, but they abuse their class names in various contexts (soU<int>()
means: Pass<int>
to the class templateU
, and construct an object by calling the default constructor without arguments). Therefore, one cannot pass template arguments to constructors.In your case, you are trying to pass template arguments in a member initializer. In that case, there's even more of a problem: It will attempt to parse and interpret
t<void>
as a base-class type and thinks you want to call the default constructor of a base class. This will fail, of course.If you can live with it, you can work it around
Given
identity
like it's defined in boost