Calling template methods in template classes

后端 未结 2 1211
夕颜
夕颜 2021-02-08 23:12

I\'m attempting to figure out why some code that I have won\'t compile and I done a fair bit of reduction an anonymizing to end up with this example:

#define NUL         


        
相关标签:
2条回答
  • 2021-02-09 00:01

    Need to add the template keyword:

    return ap->template amem<b>();
    

    Please read Where and why do I have to put the “template” and “typename” keywords? for an in-depth explanation.

    0 讨论(0)
  • 2021-02-09 00:04

    In the context where you call

    return ap->amem<b>();
    

    the name amem is a dependent name: If such a beast indeed refers to a member function template, you need to say so by adding the keyword template:

    return ap->template amem<b>();
    

    BTW, note that you shall not define NULL! If you need a definition of the abomination you should include, e.g., cstddef. Best you use just 0 or nullptr when using C++ 2011.

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