S
sip.address
Hi there,
When creating interfaces and implementations, the usual thing is doing
somethign like
class Interface {
public:
virtual void f() = 0;
virtual void g() = 0;
};
class Imp1 : public Interface {
public:
void f();
void g();
};
So we can have Interface* if = new Imp1; and so on..
But we could also use private inheritance:
class Imp1 {
protected:
void f();
void g();
};
class Interface : private Imp1 {
public:
void f() { Imp1::f(); }
...
};
What are the advantages/disadvantages of each? I believe in both cases
a level of indirection happens (through the virtual table or calling
the base class function in the second case). But probably today
compilers do some optimizations?
Any advise?
Thanks!
protected:
void f();
When creating interfaces and implementations, the usual thing is doing
somethign like
class Interface {
public:
virtual void f() = 0;
virtual void g() = 0;
};
class Imp1 : public Interface {
public:
void f();
void g();
};
So we can have Interface* if = new Imp1; and so on..
But we could also use private inheritance:
class Imp1 {
protected:
void f();
void g();
};
class Interface : private Imp1 {
public:
void f() { Imp1::f(); }
...
};
What are the advantages/disadvantages of each? I believe in both cases
a level of indirection happens (through the virtual table or calling
the base class function in the second case). But probably today
compilers do some optimizations?
Any advise?
Thanks!
protected:
void f();