private inheritance

T

Tony Johansson

Hello Experts!

I reading a book called programming with design pattern revealed
by Tomasz Muldner and here I read something that I think is wrong.

Some background
The following code shows how to inherit part of an interface. You can select
features from the base class and make them available in a derived class with
the using keyword, which effectively restores the inherited features.

class Dequeue
{
public:
Dequeue(int size=10);
virtual ~Dequeue();
void insertL(int);
void insertR(int);
int removeL();
inr removeR();
proteced:
int size;
int* elem;
int left;
int right;
};

Now to my question is the code for class definition for class Queue the same
as the pseudo-code definition of class Queue below the actual definition of
class Queue. My answer is that the definition of class Queue is not the same
as the pseudo-code definition of class Queue because of constructor and
destructor is not inherited from the base class. So these two rows should
not be included in the private section of class Queue. Do you agree with me
or I'm I wrong?
1. Dequeue(int size=10);
2. virtual ~Dequeue();

Here the actual definition of class Queue
class Queue : private Dequeue
{
public:
using Dequeue::insertL;
using Dequeue::removeR;
Queue(int size = 10)
virtual ~Queue();
};

Here pseudo-code for class Queue
class Queue
{
public:
void insertL(int);
int removeR();
Queue(int size = 10);
virtual ~Queue();
private:
Dequeue(int size=10);
virtual ~Dequeue();
int removeL();
void insertR(int);
int size;
int* elem;
int left;
int right;
};

Many thanks

//Tony
 
J

jens_theisen

They are inherited in some sense, since a call to Queue::Queue will
indirectly call Deque::Deque, and the same applies for the destructor.
This differs from overwritten function elements which are not
constructors or destructors.

Perhaps that's what Muldner was thinking.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,790
Messages
2,569,637
Members
45,346
Latest member
EstebanCoa

Latest Threads

Top