Sunday, 15 March 2015

c++ - Derive from template constuctor of template base class -



c++ - Derive from template constuctor of template base class -

just curious, ever possible inherit template class , in constructor of derived class, phone call constructor of base of operations class templated , has no arguments deduce types from?

template<typename t> struct base of operations { template<typename d> base() { // no argument of type d infer static_assert(std::is_same<t,d>::value, ""); } }; struct derived : base<int> { derived() : base<int>::base<int>() {} // there way write correctly? };

i can replace template constructor template method in particular case, still interesting question language flexibility.

what c++ standard says (section 14.8.1):

[ 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 ]

it's note, not rule, because consequence of 2 other rules, 1 in same section:

template arguments can specified when referring function template specialization qualifying function template name list of template-arguments in same way template-arguments specified in uses of class template specialization.

and 12.1

constructors not have names.

c++ templates inheritance c++11

No comments:

Post a Comment