I can't figure out how to use type aliasing for nested classes. Below is a class declaration for a linked list. I originally implemented the linkedlist class with the node and iterator classes alongside linkedlist, and am now trying to nest them inside of linkedlist. To make the class easier to read, I'd rather just use iterator instead of linkedlist::iterator everywhere, so I want to type alias it as just iterator. Below is one of my attempts, no matter what I change I end up with one error or another. This one doesn't work because the line
class linkedlist::iterator;
causes the error (g++ -std=c++11) 'iterator' in 'class linkedlist' does not name a type.
class linkedlist;
class linkedlist::iterator;
class linkedlist::node;
using iterator = linkedlist::iterator;
using node = linkedlist::node;
class linkedlist
{
public:
linkedlist();
iterator begin();
iterator end();
iterator insert(iterator pos, long data);
void print();
node* root;
node* final;
private:
class iterator
{
public:
const linkedlist* list;
node* ref;
iterator();
iterator(node& ref, const linkedlist& list);
long& operator*();
long* operator->();
iterator& operator++();
iterator& operator--();
bool operator==(iterator rhs);
bool operator!=(iterator rhs);
};
private:
class node
{
public:
long& operator*();
long data;
node* ptr_f;
node* ptr_b;
};
};