It was interesting to me:
With a tree, a root can have several children and without id. All nodes (except the root) have an identifier, and leaf nodes cannot have children. Fixed which type should be used for each depth. Thus, the leaves are always of the same type, as well as the parents of the leaves.
Since the root and nodes can have children, and only nodes have an identifier, I was wondering if the following use of multiple inheritance is acceptable:
class NodeWithId
{
private:
std::string m_id;
};
template<typename T>
class NodeWithChildren
{
private:
std::vector<T> m_nodes;
};
class Network: public NodeWithChildren<Subnet>
{
};
class Subnet: public NodeWithChildren<Machine>,
public NodeWithId
{
};
class Machine: public NodeWithChildren<Application>,
public NodeWithId
{
};
class Application: public NodeWithId
{
};
Or is there a better way to implement this?
edit:
- removed virtual
- class name changed
source
share