I'm writing a set of Linked List functions with specific requirements. I must write one function with the following requirements
string retrieve_front (llheader)
retrieves the contents of the node at the front. Does not remove the node. If the list is empty, throws an exception.
with this structure definition
struct LLnode
{
LLnode * fwdPtr; // has a pointer member
string theData; // the data within the node
};
I really want to return the hex address of the first node in addition to the data within and Im now wondering that is possible
string retrieve_front(LLnode * theLLHeader)
{
string data, report;
if (theLLHeader == nullptr)
{
throw "This list is empty";
}
else
{
data = theLLHeader -> theData;
report = "Front_Node[address: " + theLLHeader + " data: " + data + "]\n";
return report;
}
}
This is giving the following error message:
../test.cpp:103:35: error: invalid operands to binary expression ('const char *' and 'LLnode *')
report = "Front_Node[address: " + theLLHeader + " data: " + data + "]\n";
~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
I understand that a pointer is not a string (although it worked great with cout
in a different function). Ive tried using static_cast
to no avail and have seen some related questions when searching google but couldn't make sense of the answers. Is there a simple way to resolve this or should I just stick to returning the data alone, which is already a string?