0

I have some troubles with a c++ project i started. I am trying to implement basic linked list and my attempt includes proxy class in the list class for representing single node. One of the list constructors can get single parameter and initialize the first node of the list with it, but i can't pass that parameter to the proxy class' constructor. Any suggestions how to do it?

Here is some c++ code

template <class TYPE>
class list{
private:
    //Proxy class for node representation
    class node{
    private:
        node* next;
        TYPE data;
    public:
        explicit node() : next(nullptr) {}
        node (const TYPE& init) : data(init) {}
        inline node*& get_next(){
            return next;
        }
        inline TYPE& get_data(){
            return data;
        }
    };

    node* head;
    unsigned int size;
    public:
        explicit list() : head(nullptr), size(0) {}

        list(const TYPE& init) : list::node(init) {}
Zarrie
  • 325
  • 2
  • 16
  • Seems like you decided to use `list::node` syntax because you confused base class initialization with member initialization. In this case `head` is just a member of `list` and you should use member initialization syntax. It does not matter whether the class is declared inside `list` or not. – Aleksei Petrenko Jul 30 '17 at 16:05

1 Answers1

0

Well, you should refer to the instance of node rather than to the class itself. Also, keep in mind that head is a pointer in your example.

Try something like this:

list(const TYPE &init) : head(new node(init)) {}
Aleksei Petrenko
  • 6,698
  • 10
  • 53
  • 87