lundi 27 avril 2015

how to declare object of nested class present in base class

I have a c++ progrmme which I am not able to compile, following is the programm:

template <class T>
class Base
{
  protected:
   class BaseNode
    {
          public:
             int i;
 };
 protected:
    typedef void (*functionPointer)(const T &t, void *data);
    virtual void apply( const functionPointer fn,  void *data) const;
};

template <class T>
class Derived : public Base<T *>
{
  public:
    typedef void (*functionPointer)(const T *t, void *data);
    virtual void apply( const functionPointer fn,  void *data) const;
};

template <class T> void Derived<T>::apply(  const functionPointer fn,
                                                 void           *data) const
{
   BaseNode *node ;
}
int main()
{
 Derived<int > b;
}

when I try to compile it , I gets following error:

pankajk[]> g++ sample2.cpp
sample2.cpp: In member function 'virtual void Derived<T>::apply(void (*)(const T*, void*), void*) const':
sample2.cpp:26: error: 'BaseNode' was not declared in this scope
sample2.cpp:26: error: 'node' was not declared in this scope

I am new to concept of template , and really not able to figure it out that where I am doing mistake, Can somebody please tell me that where I am doing mistake. ~

Aucun commentaire:

Enregistrer un commentaire