将函数指针指定给变量

时间:2015-08-18 23:50:38

标签: c++ function-pointers

我正在尝试将函数指针赋给派生类构造函数中的变量(位于基类中的变量)。

我的代码:

class A {
 public:
  virtual void print()=0;
 protected:
  unsigned long (*func)(unsigned char *,int)
}
unsigned long A::f1(unsigned char *c,int a){...}
unsigned long A::f2(unsigned char *c,int a){...}

class B: public class A {...}
B::B(int which){
switch (which){
 case 1:
  func=f1; //first error
  break;
 case 2:
  func=f2; //second error
  break;
}

错误:

  

错误:无法将'a :: f1'从类型'long unsigned int(A ::)(unsigned char ,int)'转换为long unsigned int()(unsigned char *, INT)'

     

错误:无法将'a :: f2'从类型'long unsigned int(A ::)(unsigned char ,int)'转换为long unsigned int()(unsigned char *, INT)'

0 个答案:

没有答案