a* b::find() const
{
a* pointr = head;
return pointr;
}
This is my code but visual studio is underlining pointr in the return pointr line? What's wrong with my code?
EDIT: SORRY TYPO
a* b::find() const
{
a* pointr = head;
return pointr;
}
This is my code but visual studio is underlining pointr in the return pointr line? What's wrong with my code?
EDIT: SORRY TYPO
a* pointer = head;
return pointr;
You d not have any variable declared as pointr
in the scope of the function, How will the compiler know unless you declare it?
pointr
and pointer
are not same, there is an e
missing.
Assuming that is a typo,
Your function returns a pointer but what it points to is important in this case. If head
is a local variable or pointer without dynamic memory allocation(pointing to local object) then your pointer pointer
is pointing to a local object, which will be destroyed once the function returns and will be a dangling pointer.
Remember the Rule:
You should not return reference or pointer to an variable local to function.
You have a wrong variable returned
return pointr;
in your code. It is not defined in the scope.