polymorphism with templated classes

Hi,

I have some problems with templated classes.

I have these two classes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template<typename T>
class tree {
  protected:
   std::vector<T>  node_container;

  public:
   tree()  {}
   e ~tree() {}
   virtual insert(T *node)=0;

};

template<typename T>
class binaryTree : public tree<T> {
  public:
   insert(T *node) {
     if(node_container.empty()) ....
   }
};


The code above gives me an error.
I cannot call node_container from the insert function declared in the binaryTree class.
The compiler says:
error: ‘node_container’ was not declared in this scope


I cannot see what is the problem with the polymorphism is. The binaryTree class is public to the tree class, and the node_container is within the protected statement. Is it the template class that prevent me to inheriting from the tree class?

Any idea?

Thanks in advance
/Jesper
I assume you fixed the other syntax errors you have.

What you need to do to access node_container is:

1
2
3
4
5
6
7
template<typename T>
class binaryTree : public tree<T> {
  public:
   void insert(T *node) {
     if( tree<T>::node_container.empty() ) ....
   }
};

Thanks jsmith.
adding this-> would work too
Topic archived. No new replies allowed.