I am trying to learn c++. So I started creating a simple class Linked List. From what I understood you should put all the methods/contructors declarations in the .h file. But after I have done that I have encountered a problem, while creating the method prepend. How do I use the keyword this in the definitions file (.cpp):
Header File
#ifndef LIST_LIST_H
#define LIST_LIST_H
template <class T>
class List {
public:
List(T data, List tail): data(data), tail(tail) {}
List prepend(T data);
List get(int i);
private:
List tail;
T data;
};
#endif //LIST_LIST_H
Implementation File
#include "List.h"
template <class T>
List::List(T data, List tail): data(data), tail(tail) {}
template <class T>
List List::prepend(T data) {
return new List(data, this);
}
I tried searching for the solution but since I am new to c++ I don't know how to search it.