inheritance & polymorphism of template classes

i don't know if i'm doing anything general wrong,
but it might be a lucky guess that the templates are making all the problems,
cause i have no other way to explain that.
i try to inherit, the regular way, and the derived class does
not recognize the base fields and so.. basic stuff...

here's part of the code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
template <class Key, class Cmp  = DefaultCompare<Key> >
class AVLNode {

	friend class AVL<Key, Cmp>;
protected :
	Key * key;

	AVLNode * left;
	AVLNode * right;

	AVLNode * father;

	int height;

public :

...


and the derived one :

1
2
3
4
5
6
7
8
9
template <class Key, class Cmp = DefaultCompare<Key> >
class RankAVLNode : public AVLNode<Key,Cmp> {

	int selfRank;
	int leftRank;
	int rightRank;

public:
...


when I try to reach the field "left" from the derived class
it refers to it as something belongs to std ?!
this->left partly solves the problem, i think, cause i don't realy
know if it works.

when i try to reach the field "key" on the other hand,
it won't compile saying this field is protected..
hmm.. that's what the inheritance for... isn't it..

i have to use a lot of dynamic casts and it's ugly.. and not even has proven to work..
is there a clean way to do it?

is there a different way to treat inheritance and polymorphism of template classes?

thanks,
elad
Last edited on
Inheritance of templates is slightly different because the general purpose mechanism would allow you to
break encapsulation. In the derived class, you can use

 
AVLNode<Key,Cmp>::left


etc. (ie, use full scope)
Topic archived. No new replies allowed.