Call to template member function failing to compile

后端 未结 1 996
你的背包
你的背包 2021-01-13 02:52

I have a problem with a piece of code of the following form:

template
class Class1 {
public:
    template TypeName1*         


        
相关标签:
1条回答
  • 2021-01-13 03:38

    You should use the template keyword when you are invoking a member function template and you have a dependent name, or method1 will be parsed as a member variable of c and < as a "less than" symbol:

    c.template method1<TypeName1>();
    

    As @DrewDormann correctly points out, the reason why the template keyword is required is that a specialization of the Class1 class template could exist for the particular type argument provided, where method1 is defined as a member variable rather than a function template. Thus, the compiler must be explicitly instructed to parse method1 as the name of a function template if this is not the case.

    0 讨论(0)
提交回复
热议问题