Constructor and Copy Constructor parameters conflicting...

Hello.

I'm making a Linked-List class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
template<typename T>
struct Link
{
        T val;
	Link* next;
};

template<typename T>
class GList
{
private:
	Link<T>* il;

public:
	GList(const T& val) : il{ new Link<T>{ val,nullptr } } {}			

	GList(const GList<T>& copy)
	{
		copy.il = new Link<T>(il->val);

		Link<T>* aliasThis = il->next;
		Link<T>* aliasCopy = copy.il;

		while (aliasThis)
		{
			copy.push_tail(aliasThis->val);

			aliasThis = aliasThis->next;
		}
	}


The problem is that when in the main.cpp i write this:

1
2
3
4
5
6
GList<int> my(0);

my.push_tail(1);
my.push_tail(2);	

GList<int> my2 = GList<int>(my);


This is the error I get:
Link<T>::Link(Link<T> &&): cannot convert argument 1 from 'int' to 'const Link<T>&'

It seems like there's a conflict between the first constructor parameter and the second one's.

In my case, I want to call the copy constructor... but for some reason, the compiler calls the constructor trying to convert the list into an int...
new Link<T>(il->val);

This is attempting to call the constructor Link::Link(int) but there is no such constructor.


Also, see line 17 where the variable named copy is const? Line 19 tries to alter that const.
I think the issue is with copy.il = new Link<T>(il->val); calling a Link ctor that doesn't exist.
Thanks guys =)
Topic archived. No new replies allowed.