|
From: Janusz S. <ja...@on...> - 2002-04-28 14:58:38
|
----- Original Message -----
From: Braden McDaniel
To: ope...@li...
Cc: ck...@us...
Sent: Friday, April 26, 2002 11:31 PM
Subject: [openvrml-develop] Rearchitecture issue
>Potential solutions
>-------------------
>There are three potential solutions I see:
> 1. Without dramatically changing the design, figure out how to
> initialize the ScriptNode's NodeType before the Node
> constructor gets called.
Assuming that I understood well the problem...
According to the C++ standard the base classes are initialized in the order
as specified in the class definition, hence a member can be forced to be
initialized as the first by putting it into a separate base class that is
specified as the first parent class.
Here comes a code snippet that shows this concept:
class NodeType {};
class Node {};
class NodeTypeOwner
{
public:
NodeType m_nodeType;
};
class ScriptNode : private NodeTypeOwner, public Node
{};
Now NodeType is a member of the base class specified as the first and is
always initialized before the Node subobject. Feasibility of such a solution
depends on how complicated is initialization of the NodeType member and if
it depends on other members of the ScriptNode class.
To deal with such problems the class NodeTypeOwner may have some utility
methods to create a NodeType object, or such an object may be created in
two steps: at first be constructed enough to not crash by a base class
subobject and its initalization may finally end in the ScriptNode
constructor body.
I hope this helps.
Regards,
Janusz
|