c++ - '=' : cannot convert from 'CircularDoubleDirectedList<int>::Node *' to 'Node *' -


i have node* current store pointer node current @ "top" of list. when set new node current error:

'=' : cannot convert 'circulardoubledirectedlist<int>::node *' 'node *' while compiling class template member function 'void circulardoubledirectedlist<int>::addatcurrent(const t &)' [ t=int ] 

it 3 rows //problem comment generates errors if take them away works fine.

#include "icirculardoubledirectedlist.h"  template <typename t> class circulardoubledirectedlist; class node;  template <typename t> class circulardoubledirectedlist :     public icirculardoubledirectedlist<t>{ public:     //variables     node* current;     int nrofelements;     direction currentdirection;      //functions     circulardoubledirectedlist();     ~circulardoubledirectedlist();     void addatcurrent(const t& element) override;  private:     class node     {     public:         t data;         node* forward;         node* backward;          node(const t& element);     };  }; template <typename t> void circulardoubledirectedlist<t>::addatcurrent(const t& element){     node* newnode = new node(element);     newnode->data = element;     if (this->nrofelements == 0){         newnode->forward = newnode;         newnode->backward = newnode;     }     else{         this->current->forward = newnode; // problem         this->current->forward->backward = newnode; // problem     }     this->current = newnode; //problem } 

when forward declare node being outside of class here:

template <typename t> class circulardoubledirectedlist; class node; 

that declaring type node in global namespace. ::node. then, within class declaration, current takes on that type:

template <typename t> class circulardoubledirectedlist      : public icirculardoubledirectedlist<t> { public:     node* current;   // pointer ::node. }; 

then provide declaration of circulardoubledirectedlist<t>::node. not same type ::node. gets looked first name resolution rules. in here:

template <typename t> void circulardoubledirectedlist<t>::addatcurrent(const t& element){     node* newnode = new node(element); // newnode pointer                                        // circulardoubledirectedlist<t>::node 

but current pointer still-incomplete type ::node. hence error - have inadvertently created two types named node.

if you're going forward-declare node, have inside class:

template <typename t> class circulardoubledirectedlist      : public icirculardoubledirectedlist<t> {     class node; // it's circulardoubledirectedlist<t>::node }; 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -