vendredi 27 février 2015

C++ create a usable method in the child class


This my base class



class Base {
protected:
int number;
public:
Base(int num);
virtual void display() = 0;
};


these two classes have inherited Base.



class Derived: public Base {
public:
Derived(int num);
void display(){cout <<"hello";}
void other();
};

class Derived2: public Base {
public:
Derived(int num);
void display(){cout <<"hello other";}
};


this class allows me to just instantiate my two classes Derived and Derived2



class Foo{
private:
Base * toto[2];
public:
Foo(){
toto[0] = new Derived;
toto[1] = new Derived2;
}

void doSomething();
}


and I want to do this



void Foo::doSomething(){
toto[0]->other();
}


thank's.




Aucun commentaire:

Enregistrer un commentaire