C++ 需要在派生类中专门化具有成员的基类

C++ 需要在派生类中专门化具有成员的基类,c++,templates,derived-class,member-function-pointers,C++,Templates,Derived Class,Member Function Pointers,我有一个管理方法指针的类: template<class C> class Prioritizer { public: typedef int (C::*FNMETHOD) ( ); typedef std::map<unsigned int, std::vector<FNMETHOD> > methlist; // associate priority values with methods virtual void setPrio(u

我有一个管理方法指针的类:

template<class C>
class Prioritizer {
  public:
  typedef int (C::*FNMETHOD) ( );
  typedef std::map<unsigned int, std::vector<FNMETHOD> > methlist;

  // associate priority values with methods
  virtual void setPrio(unsigned int iPrio, FNMETHOD f);

  // call all methods for given priority
  virtual void execPrio(C *pC, int iPrio);
}
现在我有一个基类拥有这样一个优先级对象。但这个对象必须只在派生类中专用(否则我只能使用基类的方法)。 最后,我希望能够有一个从Base派生的类集合(例如vector),并调用由它们的优先级对象组织的方法

我想到的最好的办法是:

template<class C>
class Base {
  public:
    // ... other stuff ...
    Prioritizer<C> m_prio;
}

class Der1 : public Base<Der1> {
   public:
     virtual int testDer1();
     int init() {
       m_prio->setPrio(7, testDer1);
     }; 
}
模板
阶级基础{
公众:
//…其他东西。。。
优先者m_prio;
}
类Der1:公共基{
公众:
虚拟int testDer1();
int init(){
m_prio->setPrio(7,testDer1);
}; 
}
对我来说,用一个即将定义的类专门化一个模板似乎很尴尬

有更好的办法吗

多谢各位
Jody

您可以在地图中存储
std::function
对象或其boost模拟。并在将其传递给
setPrio
函数时将任何具体方法绑定到此函数对象。

谢谢!我花了一段时间才明白我必须使用std::bind,但现在它可以工作了!
template<class C>
class Base {
  public:
    // ... other stuff ...
    Prioritizer<C> m_prio;
}

class Der1 : public Base<Der1> {
   public:
     virtual int testDer1();
     int init() {
       m_prio->setPrio(7, testDer1);
     }; 
}