c++ - Can a class have a templated constructor without arguments? -
c++ - Can a class have a templated constructor without arguments? -
this question has reply here:
derive template constuctor of template base of operations class 3 answersi have want have class looks like:
template <typename t> class foo { public: template <typename s> foo() { //... } };
but cannot figure out how phone call constructor. obviously, can create work giving foo() argument of type s can done without arguments?
--ron
you can't pass template arguments explicitly constructor template. constructors don't have names.
[ note: because explicit template argument list follows function template name, , because conversion fellow member function templates , constructor fellow member function templates called without using function name, there no way provide explicit template argument list these function templates. — end note ]
although can name constructor using syntax foo<int>::foo
, can used in ways aren't of involvement here:
in lookup in constructor acceptable lookup result , nested-name-specifier nominates class c
: — if name specified after nested-name-specifier, when looked in c
, injected-class-name of c
(clause 9), or — […] the name instead considered name constructor of class c
. […] such constructor name shall used in declarator-id of declaration names constructor or in using-declaration.
c++ templates
Comments
Post a Comment