I am compiling my code with g++ -g and I am getting the error message in the title.
The error is related to a function I have made, it’s signature being:
void addHead( Elem *&start , Elem *newStart );
and I am passing this function these two variables:
Elem * head;
Elem * tempEl;
so that it looks like this:
addHead( *head , *tempEl );
The actual function is:
void addHead( Elem start , Elem newStart )
{
Elem listItem;
listItem = newStart;
*listItem.next = start;
start = listItem;
}
It pre-pends the second argument to the the beginning of a linked-list starting at the first argument.
I have been pulling my hair out with this one. No matter what I do I keep getting this error!
cannot convert Elem to Elem* for argument 1 to void addHead(Elem*, Elem*)
Edit: Forgot this error is in there too:
error: invalid initialization of reference of type Elem*& from expression of type Elem
It’s being pretty specific: You’re passing an
Elem, but it takes anElem*. In particular,headis of typeElem*, but you are passing*head: of typeElem.Also, your definition signature doesn’t match your definition, so even when you fix the call, you will get a linker error when it can’t find
addHead(Elem*, Elem*). Definitions must exactly their signatures (more correctly, declarations). Of course, neither of these changes will fix the actual implementation ofaddHead(), but that’s your homework 🙂