I get a compile error for a create function I use with the insert function. It works though when I do the different calls in the if clause, but I want to move it to a seperate create function instead. Any help regarding the compile error I get is appreciated
|76|error: cannot convert list_link*' tosorted_list::list_link*' in assignment|
The header file
class sorted_list
{
public:
sorted_list(); // Constructor declaration
~sorted_list(); // Destructor declaration
void insert(int key, double value);
void print();
private:
class list_link
{
// Declarations
public:
my_key_type key;
my_value_type value;
list_link *next;
};
list_link* first;
};
The functions
void sorted_list::insert(int key, double value)
{
list_link *curr, *prev;
curr = first;
while(curr)
{
prev = curr;
curr = curr->next;
}
if(first == 0 || prev == 0) //if empty or add first
{
cout << "empty list" << endl;
list_link *new_link = new list_link;
new_link->key = key;
new_link->value = value;
new_link->next = 0;
first = new_link;
}
else
{
cout << "add" << endl;
prev->next = create(key, value, 0);
}
}
create function
list_link* create(my_key_type key, my_value_type value, list_link* next)
{
// creates the node;
list_link *new_link = new list_link;
// add values to the node;
new_link->key = key;
new_link->value = value;
new_link->next = next;
return new_link;
}