开发者

Is it possible to have a templated constructor like 'template<class T> X(){}'?

struct X{
    template<class T>
    X(){}
}开发者_如何学JAVA;

Is it possible to instantate such a type?


Yes, it is possible to have such a constructor, but it's impossible to call it. All the template parameters of a templated constructor must be deduced from the parameter list or have a default value. In Your example you can't instantiate the class.

[temp.mem]

[ Note: Because the explicit template argument list follows the function template name, and because conversion member function templates and constructor member function templates are called without using a function name, there is no way to provide an explicit template argument list for these function templates. —end note ]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜