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
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