Odd error message when instantiating a template class

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>;

        ForestNode( const NODETYPE &);
        NODETYPE getTag() const;
        NODETYPE tag;
        ForestNode<NODETYPE> *leftChild;
        ForestNode<NODETYPE> *sibling;

Any ideas?


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

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

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 );

Need Your Help

Emacs preview-latex

emacs elisp dot-emacs

I use preview-latex for displaying LaTeX results in an Emacs window. I use preview-at-point to toggle back and forth between code and output. However if I am not on Latex code (by mistake, maybe I ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.