Template partial specialization with multiple template argument error

后端 未结 2 2012
深忆病人
深忆病人 2020-12-30 15:33

When I use template partial specialization on a class with one template argument, I can specialize a method like this:

#include 

template<         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 16:15

    You cannot partially specialise functions – this includes member functions. You can only partially specialise the whole class:

    template< typename T, std::size_t Dim >
    class Test
    {
    public:
      int foo()
      {
        return 0;
      }
    };
    
    template< typename T >
    class test< T, 1 >
    {
    public:
      int foo()
      {
        return 1;
      }
    };
    

    (I’ve defined the functions inline here; that of course isn’t necessary.)

提交回复
热议问题