views:

32

answers:

2

Hi all, I am getting an error I do not understand. There was even a similar question asked on SO that I found, but the fix given is already in my code.

I am getting an error in this line:

ForestNode<NODETYPE> foo = new ForestNode<NODETYPE> ForestNode(bar);

that reads :

\project 4\forest.h|85|error: expected ',' or ';' before 'ForestNode'

My class forestnode is defindes as such:

template<typename NODETYPE> class Forest;

template<typename NODETYPE> class ForestNode
{
    friend class Forest<NODETYPE>;

    public:
        ForestNode( const NODETYPE &);
        ~ForestNode();
        NODETYPE getTag() const;
    private:
        NODETYPE tag;
        ForestNode<NODETYPE> *leftChild;
        ForestNode<NODETYPE> *sibling;
};

Any ideas?

+1  A: 

You have the type name twice in the constructor call, try:

ForestNode<NODETYPE> foo = new ForestNode<NODETYPE>(bar);
heavyd
hah wow. I should go to sleep, that's what coding while tired does to you. Wasn't even thinking about what that meant exactly. Thanks.
joedillian
+1  A: 

Besides having 2 constructors on one line, you can not allocate the pointer to the variable. You either have to do this :

ForestNode *foo = new ForestNode;

or do this :

ForestNode<NODETYPE> foo;

or this :

ForestNode<NODETYPE> bar;
ForestNode<NODETYPE> foo( bar );
VJo