c++ - Forwarding template parameters -
i trying forward template parameter parent class (from subclass), getting following error when trying so;
test.cc:9:46: error: type/value mismatch @ argument 1 in template parameter list ‘template<class a, class b> class baseclass’ class subclass : public baseclass<subclass, b> { ^ test.cc:9:46: error: expected type, got ‘subclass’
here code trying run;
#include <cstdlib> template<typename a, typename b> class baseclass { }; template<typename b> class subclass : public baseclass<subclass, b> { // trying forward b second parameter }; int main(void) { return exit_success; }
i have tried prefixing b
typename
, following error instead;
test.cc:9:55: error: type/value mismatch @ argument 1 in template parameter list ‘template<class a, class b> class baseclass’ class subclass : public baseclass<subclass, typename b> { ^ test.cc:9:55: error: expected type, got ‘subclass’ test.cc:9:55: error: template argument 2 invalid
template<typename b> class subclass : public baseclass<subclass<b>, b> // ^^^ { };
subclass
injected name can used refer subclass<b>
in scope of subclass
. outside, name of class template (that it, requires template parameter list <>
form type).
§ 9 [class]/p2:
the class-name inserted scope of class itself; known injected-class-name.
§ 3.3.2 [basic.scope.pdecl]/p8:
the point of declaration injected-class-name (clause 9) following opening brace of class definition.
§ 14.6.1 [temp.local]/p1:
like normal (non-template) classes, class templates have injected-class-name (clause 9). injected-class-name can used template-name or type-name. when used template-argument-list, template-argument template template-parameter, or final identifier in elaborated-type-specifier of friend class template declaration, refers class template itself. otherwise, equivalent template-name followed template-parameters of class template enclosed in
<>
.
Comments
Post a Comment