I have this structures in C++11
struct A {
int idA;
void setId(int i) { idA = i;}
int getId() { return idA;}
virtual void foo() = 0;
};
struct B {
int idB;
void setId(int i) { idB = i;}
int getId() { return idB;}
virtual void foo2() = 0;
};
struct AB : public A, public B
{
void foo() override {}
void foo2() override {}
};
Now in main I can call it like this:
AB * ab = new AB();
ab->B::setId(10);
but I dont really like it.
Is there any other solution? Methods setId/getId
from struct A
are not needed in AB
. I just did the inheritance, because I need foo()
and other stuff from A
, but all other methods are unique.
Aucun commentaire:
Enregistrer un commentaire