dimanche 26 avril 2015

Inheritance and template in C++: Why following peace of code in not compiling

I have a simple c++ program , which I am not able to compile , although i tried to search in google and try to read about template , inheritance and vector , but i didn't got any clue that what mistake I am doing, Can anyone please help me!! following is the code:

template <class T>
class Base
{
  public:
    int entries;
};
template <class T>
class Derive : public Base<T *>
{
  public:
     int j;
     void pankaj(){j = entries;}
    void  clear();

};
template <class T> void Derive<T>::clear()
{
  int i;
  int j=entries;
};
int main()
{
Derive b1;
}

And I am getting following error: pankajkk> g++ sample.cpp

sample.cpp: In member function 'void Derive<T>::pankaj()':
sample.cpp:14: error: 'entries' was not declared in this scope
sample.cpp: In member function 'void Derive<T>::clear()':
sample.cpp:22: error: 'entries' was not declared in this scope
sample.cpp: In function 'int main()':
sample.cpp:26: error: missing template arguments before 'b1'
sample.cpp:26: error: expected `;' before 'b1'

Thanks!!

Aucun commentaire:

Enregistrer un commentaire