Reputation: 31
First time asking so be gentle.
I am having a problem with a returning a custom type for a function. To be more specific, I have a linked list, and I am writing a function that traverses to the end of the list and returns a pointer to that node. Unfortunately, I am getting a pesky error:
"Return type out-of-line definition of mySpace::CDAL::tailNode differs from that in the declaration"
The header file contains within the "mySpace" namespace and the template class CDAL
private:
struct Node
{....};
the function header
Node* tailNode();
and in the .cpp
template <typename T>
struct Node* mySpace::CDAL<T>::tailNode()
{...}
I tried using struct because someone had mentioned for non-typedef declarations you sometimes would need it, and I no longer received the unknown type error, but received this instead.
Thanks in advance for any help.
Upvotes: 2
Views: 8016
Reputation: 96810
Node
is declared within mySpace::CDAL<T>
so its name has to be qualified in the definition:
template <typename T>
struct typename mySpace::CDAL<T>::Node* mySpace::CDAL<T>::tailNode()
{...}
struct
also isn't needed. Taking it out won't make a difference.
Upvotes: 2