A
Arne Claus
I've got a tricky problem here.
I try to create an object-hierarchie, based on a template base class like
template <class T> class Node {
addChild(Node<T> *) =0;
// the Node-Container wil be defined in the base classes
};
The problem is, that the classes derived from Node represent different
forms of hierarchies, which all can use a different paramter T. This
paramter T however has to be a class dervied from a specific base class
(because I need specific functions in some member functions).
The Idea is, that hierarchies of a parameter T can only add other
hierarchies that use the same parameter T (to e.g. save conversion
operations).
template <class T> class HierarchieTypeA : public Node<T> {
};
template <class T> class HierarchieTypeB : public Node<T> {
};
HierarchieTypeA<a> obj1a; // where a is derived from "base"
HierarchieTypeB<a> obj2a;
HierarchieTypeA<b> obj1b; // where b is derived from "base"
HierarchieTypeB<b> obj2b;
obj1a.addChild(obj1a); // allowed
obj1a.addChild(obj2a); // allowed
obj1a.addChild(obj1b); // not allowed
obj1a.addChild(obj2b); // not allowed
The problem is, that I see no elegant way to prevent the template
paramter from being an int or float or whatever. I thought of
specialising the Node container like
vector<Node<base>*>
But that would involve a lot classname lookups and castings in some cases.
So if somebody knows a solution for this I would really be thankfull ^^
Arne
I try to create an object-hierarchie, based on a template base class like
template <class T> class Node {
addChild(Node<T> *) =0;
// the Node-Container wil be defined in the base classes
};
The problem is, that the classes derived from Node represent different
forms of hierarchies, which all can use a different paramter T. This
paramter T however has to be a class dervied from a specific base class
(because I need specific functions in some member functions).
The Idea is, that hierarchies of a parameter T can only add other
hierarchies that use the same parameter T (to e.g. save conversion
operations).
template <class T> class HierarchieTypeA : public Node<T> {
};
template <class T> class HierarchieTypeB : public Node<T> {
};
HierarchieTypeA<a> obj1a; // where a is derived from "base"
HierarchieTypeB<a> obj2a;
HierarchieTypeA<b> obj1b; // where b is derived from "base"
HierarchieTypeB<b> obj2b;
obj1a.addChild(obj1a); // allowed
obj1a.addChild(obj2a); // allowed
obj1a.addChild(obj1b); // not allowed
obj1a.addChild(obj2b); // not allowed
The problem is, that I see no elegant way to prevent the template
paramter from being an int or float or whatever. I thought of
specialising the Node container like
vector<Node<base>*>
But that would involve a lot classname lookups and castings in some cases.
So if somebody knows a solution for this I would really be thankfull ^^
Arne