C ++: Не удается объявить поле абстрактного типа

Я получаю эту ошибку при компиляции -> не могу объявить поле M1 :: sc абстрактным типом I1, потому что следующие виртуальные функции являются чистыми внутри I1. Пожалуйста, помогите.

   class I1
    {    
    public:  
        virtual void a(int dir) = 0;
        virtual void b() = 0; 
        virtual void c() = 0; 

        void a(int dir) {  
        ....
        }

        void b() {  
        ....
        }

        void c() {  
        ....
        }
    };

    class I2 : public I1
    {    
    public:  


        void a(int dir) {  
        ....
        }

        void b() {  
        ....
        }

        void c() {  
        ....
        }
    }; 

    class M1 : public G1
    {
    protected:
    I1 sc;
    public:
       int dir = 4;
       sc.a(dir);
    };

Полный код можно найти на http://pastebin.com/PFrMTJuF . class Parent { общедоступные: void (* funcPointer) (); void (* funcPointer2) (Родитель * _this); void (Child :: * funcPointer3) (); }; class Child: публичный родитель { public: void TestFunc () {} ...

class Child;
class Parent
{
public:
  void (*funcPointer)();
  void (*funcPointer2)(Parent* _this);
  void (Child::*funcPointer3)();
};

class Child: public Parent
{
public:
  void TestFunc(){

  }
  void Do(){
    Parent p;
    p.funcPointer=TestFunc; // error, '=': cannot convert from 'void (__thiscall Child::* )(void)' to 'void (__cdecl *)(void)'
    p.funcPointer2=TestFunc; // error too, '=': cannot convert from 'void (__thiscall Child::* )(void)' to 'void (__cdecl *)(Parent *)'
    p.funcPointer3=TestFunc; //this works
    p.funcPointer3=&Child::TestFunc; // this works too.
    p.funcPointer3();    // error, term does not evaluate to a function taking 0 arguments
  }
};

Как передать функцию-член в указатель функции, а затем как мне затем вызвать этот указатель функции?

10
задан Jonathan Mee 30 June 2016 в 13:08
поделиться