Click here to Skip to main content
15,901,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm tring to find a certain element in a list but it always give me this error
There are no conversions from integral values to pointer-to-member values


What I have tried:

Node<T>* GetptrTo(T k)
	{
		Node<T>* ptr = Head;
		while (ptr != NULL)
		{
			if (ptr->getItem == k) { return ptr; }
			ptr = ptr->getNext();
		}
		

	}
Posted
Updated 23-Dec-20 7:32am
v2

1 solution

Without seeing the header that declares the Node class we can only guess. My guess is getItem is a method of the class so you need have parenthesis to call it : getItem().

Note - the GetptrTo function also needs to return something. I would guess it needs to return ptr.

Guessing again, it should probably look something like this :
C++
Node<T>* GetPtrTo( T k )
{
    Node<T>* ptr = getHead();
    while( ptr )
    {
        if( ptr->getItem() == k )
            break;
        ptr = ptr->getNext();
    }
    return ptr;
}
One last thing - isn't GetptrTo a method of the Node class? It looks like it should be to access the Head item. I would make a method for the class to access the list's Head item.
 
Share this answer
 
v3
Comments
CPallini 23-Dec-20 17:23pm    
5.
Rick York 24-Dec-20 14:26pm    
Thanks.
Stefan_Lang 24-Dec-20 5:48am    
Great analysis on all counts. getItem() is spot on: the compiler tries to do a conversion, and this is the only location in the code that could cause this exact error message. I was also wondering about this function accessing the symbol Head: either this is a global variable, which is bad (but not fatal), or it is a data member of the list class, in which case this function is meant to be an implementation of a method, but is missing the class qualifier. (which would result in another compiler error)
Rick York 24-Dec-20 14:25pm    
thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900