I am encountering this problem frequently and I believe a move constructor is in order but I think the copy constructor is the problem and hiding it does not seem to work.
The code:
template <class T>
class LinkedList{
public:
//
LinkedList() {}
LinkedList(const T &data);
LinkedList(const T &data, const LinkedList &node);
LinkedList(const LinkedList &object);
LinkedList &operator=(const LinkedList &object);
~LinkedList() {}
std::shared_ptr<LinkedList> push_back(const T& data);
private:
T data;
std::unique_ptr<LinkedList> link;
std::unique_ptr<LinkedList> LinkFactory(const LinkedList &node);
std::shared_ptr<LinkedList> CreateStartNode(const T &data);
std::shared_ptr<LinkedList> CreateNode(const T &data, const LinkedList &node);
};
The particular line where the error is occurring is:
LinkedList<T>::LinkedList(const LinkedList<T> &object) : data(object.data),
link(std::move(object.link)) {}
I am attempting to move, rather than copy, the link inside the copy constructor to no avail. If a move constructor is designed rather than synthesized, would that be better?