C++ template partial specialization - specializing one member function only

后端 未结 5 1285
执念已碎
执念已碎 2020-12-28 21:16

Bumped into another templates problem:

The problem: I want to partially specialize a container-class (foo) for the case that the objects are pointers, and i want to

5条回答
  •  囚心锁ツ
    2020-12-28 21:55

    Create base class for single function deleteSome

    template
    class base {
    public:
      void deleteSome (T o) { printf ("deleting that object..."); }
    }
    

    Make partial specialization

    template
    class base {
    public:
      void deleteSome (T * o) { printf ("deleting that PTR to an object..."); }
    }
    

    Use your base class

    template 
    class foo : public base {
     public:    
       void addSome    (T o) { printf ("adding that object..."); 
    }    
    

提交回复
热议问题