- I have a class
A
that I can not edit:
class A{
public:
int thisCoolFuntion(){
return 0;
}
};
- I want to create a class that uses
thisCoolFuntion()
(let's call it classB
orC
) I want the user to be able to create an instance of
B
orC
, but that he doesn't have access tothisCoolFuntion()
.I thought one solution was to do a
private
inheritance:
class B : A{
public:
int member;
void setBMember(){
member = thisCoolFuntion();
}
};
- I also thought on having a
private
member of typeA
:
class C{
A memberA;
int member;
public:
void setCMember(){
member = memberA.thisCoolFuntion();
}
};
- These 2 solutions seem to work:
int main(int argc, const char * argv[]) {
// insert code here...
B b;
b.setBMember();
//b.thisCoolFuntion(); --> Error!
C c;
c.setCMember();
//c.memberA.thisCoolFuntion(); --> Error!
return 0;
}
Question: how should I compare theses 2 solutions? how can I choose which one is more appropriated for my project? is one of them faster? or one takes more memory? is one of these more generally recognized by users?