jeudi 30 janvier 2020

pass function to class as parameter C++

there is error here(but when i try to send non //class function its workin); like when i try to add normal void zad1(){somethin...} its works but when i try to add function from class its not :?

 //Class that send function//
    class Lekcja1 : public ZadanieW {
    private:
        int numerZad;
    public:
        Lekcja1(int num) {
            this->numerZad = num;
        };
        ~Lekcja1() {};
        void tab();
         virtual void LekcjaChose();
    };
    /*void Zad12() {
        cout << "dupa" << endl;
    }*/
    void Lekcja1::tab() {
        cout << "dupa" << endl;
    };
     void Lekcja1::LekcjaChose() {
        wyborZadania* obj = new wyborZadania(numerZad,tab);//there is a problem
        delete obj;
    }
    //Class that takin function//
    class ZadanieW {
    public:
        virtual void LekcjaChose() = 0;
    };
    class wyborZadania{
    public:
        int _chose;
    public:
        wyborZadania(int num,void (*tab)()) {
            this->_chose = num;
            switch (_chose)
            {
            case 1:
                (*tab)();
                break;
            default:
                break;
            }
        }
        ~wyborZadania() {}
    };

Aucun commentaire:

Enregistrer un commentaire