I am busy with an assignment an I am getting an error from the compiler. I’ve got 4 yrs C# experience nil in C++.
I’m getting the error “Invalid conversion from nodeType, initializing argument 1 of void linkedListType::deleteNode(const Type&) [with Type = int]’ ” on the line deleteNode(current->link); of this function:
template<class Type>
void linkedListType<Type>::deleteNodePosition(int position)
{
nodeType<Type> *current; //pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
if(first == NULL) //Case 1; list is empty.
cerr<<"Can not delete from an empty list.\n";
else
{
current = first;
int counter = 0;
while(current != NULL && counter <= position)
{
trailCurrent = current;
current = current->link;
counter++;
} // end while
deleteNode(current->link);
}
deleteNode is defined as :
template<class Type>
void linkedListType<Type>::deleteNode(const Type& deleteItem)
{
.....
and nodeType is defined as:
struct nodeType
{
Type info;
nodeType<Type> *link;
};
and I am calling the offending function with this:
linkedListType<int> llist;
llist.insertFirst(99);
llist.insertLast(94);
llist.deleteNodePosition(2);
Please help?
Well, the problem is pretty straightforward. This:
is defined to have type
But this function that you are trying to pass it to
accepts an argument of type
Since
nodeType<Type>*isn’t at all the same thing asconst Type&, that function can’t accept that parameter.Without seeing the rest of your code it’s hard to infer what you meant to do, but I would think that based on its name, the
deleteNodefunction should accept a node (i.e. anodeType<Type>*) rather than a piece of data contained by a node.