C++ '*' 标记之前的预期构造函数、析构函数或类型转换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2271390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expected constructor, destructor, or type conversion before '*' token
提问by Freezerburn
I honestly have no idea why this is happening. I checked, double-checked, and triple-checked curly braces, semicolons, moved constructors around, etc. and it still gives me this error.
老实说,我不知道为什么会这样。我检查、双重检查和三重检查大括号、分号、移动构造函数等,它仍然给我这个错误。
Relevant code follows.
相关代码如下。
BinTree.h
二进制树
#ifndef _BINTREE_H
#define _BINTREE_H
class BinTree
{
private:
struct Node
{
float data;
Node *n[2];
};
Node *r;
Node* make( float );
public:
BinTree();
BinTree( float );
~BinTree();
void add( float );
void remove( float );
bool has( float );
Node* find( float );
};
#endif
And BinTree.cpp
和 BinTree.cpp
#include "BinTree.h"
BinTree::BinTree()
{
r = make( -1 );
}
Node* BinTree::make( float d )
{
Node* t = new Node;
t->data = d;
t->n[0] = NULL;
t->n[1] = NULL;
return t;
}
回答by Michael Burr
Because on the line:
因为上线了:
Node* BinTree::make( float d )
the type Node
is a member of class BinTree
.
类型Node
是 的成员class BinTree
。
Make it:
做了:
BinTree::Node* BinTree::make( float d )