Specialization of templated member function in templated class

前端 未结 2 949
情歌与酒
情歌与酒 2020-11-28 14:32

I have a templated class with an templated member function

template
class A {
public:
    template
    CT function();
};
         


        
2条回答
  •  甜味超标
    2020-11-28 15:00

    You can use overload, if you change the implementation.

    template 
    class Foo
    {
    public:
      template 
      CT function() { return helper((CT*)0); }
    
    private:
      template 
      CT helper(CT*);
    
      T helper(T*) { return (T)0.0; }
    
      bool helper(bool*) { return false; }
    };
    

    Simple and easy :)

提交回复
热议问题