templates - C++ implementation of a singly linked list -


i'm trying implement singly linked list in c++. here's node.

template <typename t> struct snode{     explicit snode(const t& val, snode* ptr=0) : value(val), next(ptr){}     t value;     snode* next; }; 

here's slist

template <typename t> class slist{ public:     class iterator;      slist() : head_(0){}      //need assign copy constructor     //assignment operator     //destructor      bool empty() const{ return (head_ == 0);}     int size() const;     iterator begin();     iterator end();      void insert(iterator p, const t& t);     void erase(iterator p);  private:     snode<t>* head_; }; 

and here's iterator

class iterator{ public:     explicit iterator(snode<t>* node = 0) : node_(node){}      t& operator*(){return node_->value; }     t* operator->(){return &(node_->value); }      iterator& operator++(){         if(node_ != 0)node_ = node_->next;         return *this;     }     iterator operator++(int){         iterator tmp = *this;         if(node_ != 0) node_ = node_->next;         return tmp;     }     bool operator==(const iterator& iter) const{return (node_ == iter.node_);}      bool operator!=(const iterator& iter) const{ return (node_ != iter.node_);}      snode<t>* node_; }; 

the issue since i've declared iterator inside slist, should have access generic t object in iterator definition. isn't happening. continue squiggly on t saying

can't resolve symbol t 

you not showing explicit instantiated (or casted) type. "t" can't compile because can't resolve "t" reconciles to. iterator class needs "templated" or explicitly casted within class in order reconcile.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -