Thursday, November 12, 2009

C++ Template with a Private Class: "expected constructor, destructor, or type conversion before '*'"

Within a class or function template, it is necessary label (with the
"typename" keyword) any name-dependent type - bytes.com

typename BST<TypeT>::BSTNode * BST<TypeT>::BSTNode::Insert(TypeT const& v)
{
//Implementation
}

I was creating a BST and LinkedList with private node classes and I ran into this error:
"expected constructor, destructor, or type conversion before '*'"

There are 3 root causes:
* referencing "BST" instead of "BST<TypeT>"
* referencing "BST<TypeT>::BSTNode *" as a return value instead of "typename BST<TypeT>::BSTNode *"
* attempting to use the standard ".h" / ".cpp" separation in the first place rather than just garbling everything together

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home