vendredi 27 mai 2016

Design base class for derived classes with functions having different signatures

class B {
public:
    virtual void foo(?);
}
class D1 : public B {
public:
    void foo(T1*);
}
class D2 : public B {
public:
    void foo(T2*);
}

B* b1 = new D1();
B* b2 = new D2();

T1 and T2 may not be related.

How do I design the classes such that called b1 and b2 call the correct foo with correct type?

Can use upto c++14.

Aucun commentaire:

Enregistrer un commentaire