A
Allan Bruce
I have a few questions which I am unsure about, and would appreciate if
somebody could clarify them.
If I have the following example class:
class List
{
public:
List();
virtual ~List();
// ...
protected:
Node *mHeadNode;
};
This is a working list that I have implemented to test my programming
skills. Now I want to create another type of list derived from this (for
synchrnozing memory access, but thats not the point of the question). This
new class is basically a wrapper which does some initialising on each method
call, then executes the List:: method and then some cleaning up. I have
everything fine apart from I want to be sure about the constructors and
destructors. If I have my new class defined as:
class ListSync : public List
{
ListSync();
virtual ~ListSync();
then when I create a new ListSync it executes the constructor of List first
followed by the constructor of ListSync, correct? What happens when I
delete myListSync? Does it only call the destructor of ListSync?
The last question I have is: What if, in my new class ListSync, I want to
change the type of mHeadNode to AdvancedNode. I take it I cant merely
define it as:
class ListSync : public List
{
ListSync();
virtual ~ListSync();
// ...
protected:
AdvancedNode *mHeadNode;
};
Because when the following line is executed in List::
mHeadNode = new Node();
A Node will be created instead of an AdvancedNode. Is there a way to make
ListSync use an AdvancedNode instead of a Node?
Thanks,
Allan
somebody could clarify them.
If I have the following example class:
class List
{
public:
List();
virtual ~List();
// ...
protected:
Node *mHeadNode;
};
This is a working list that I have implemented to test my programming
skills. Now I want to create another type of list derived from this (for
synchrnozing memory access, but thats not the point of the question). This
new class is basically a wrapper which does some initialising on each method
call, then executes the List:: method and then some cleaning up. I have
everything fine apart from I want to be sure about the constructors and
destructors. If I have my new class defined as:
class ListSync : public List
{
ListSync();
virtual ~ListSync();
then when I create a new ListSync it executes the constructor of List first
followed by the constructor of ListSync, correct? What happens when I
delete myListSync? Does it only call the destructor of ListSync?
The last question I have is: What if, in my new class ListSync, I want to
change the type of mHeadNode to AdvancedNode. I take it I cant merely
define it as:
class ListSync : public List
{
ListSync();
virtual ~ListSync();
// ...
protected:
AdvancedNode *mHeadNode;
};
Because when the following line is executed in List::
mHeadNode = new Node();
A Node will be created instead of an AdvancedNode. Is there a way to make
ListSync use an AdvancedNode instead of a Node?
Thanks,
Allan