Difference between template name and template id

后端 未结 3 549
暖寄归人
暖寄归人 2020-12-09 12:49

C++ Standard

Section 14/2 :

In a function template declaration, the declarator-id shall be a template-name (i.e.,

3条回答
  •  眼角桃花
    2020-12-09 13:21

    From C++ Templates: The Complete Guide By David Vandevoorde, Nicolai M. Josuttis

    8.3

    Explicit template arguments: A template name can be followed by explicit template argument values enclosed in angle brackets. The resulting name is called a template-id.

    For example:

    template 
    struct Demo{ 
        // ... 
    };
    
    int main()
    {
       Demo  d; // Demo is the template name, Demo is the template-id
       // ...
    }
    

    In a function template declaration, the declarator-id shall be a template-name (i.e., not a template-id).

    For example (from what I have understood):

    class A {
    public:
        template  void f(T);
        template  struct X { };
    };
    class B : public A {
    public:
        using A::f;     // fine
        using A::X      // fine
    
    };
    class C : public A {
    public:
        using A::f;     // ill formed, declarator-id shall not be a template id
        using A::X   // ill formed, declarator-id shall not be a template id
    
    };
    

    Someone please correct me if I am wrong.

提交回复
热议问题