实例化模板类时出现奇怪的错误消息
我收到一个我不明白的错误。我发现甚至在 SO 上提出了类似的问题,但给出的修复已经在我的代码中。
我在这一行中收到错误:
ForestNode<NODETYPE> foo = new ForestNode<NODETYPE> ForestNode(bar);
内容为:
\project 4\forest.h|85|error: Expected ',' or ';'在'ForestNode'之前
我的类forestnode是这样定义的:
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;
};
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在构造函数调用中有两次类型名称,请尝试:
You have the type name twice in the constructor call, try:
除了一行上有 2 个构造函数之外,您还不能将指针分配给变量。你要么必须这样做:
ForestNode *foo = new ForestNode;
或执行此操作:
或执行此操作:
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 :
or this :