c++中的可视化语法错误
visual syntax error in c++
i wana
在c++中创建了一个bst
树,但我在这段代码中有一个语法错误:
#pragma once
#include "BSTNode.h"
using namespace std;
class BST
{
private:
BSTNode* root;
public:
BST(void);
bool insert(int );
int search(int);
~BST(void);
};
CCD_ 3为
#pragma once
#include "BST.h"
class BST;
class BSTNode
{
friend class BST;
private:
int data;
BSTNode * LeftChild, *RightChild;
public:
BSTNode(void);
int getData();
~BSTNode(void);
};
我的错误是:
Error 1 error C2143: syntax error : missing ';' before '*'
我认为dont
有错误。请帮帮我!
您有一个循环include,包含2个文件,由于#Pragma一次,两个文件都只包含一次,因此首先解析BSTNode并包含BST,但BST不再包含BSTNode(因为它是Pragma一)。
这导致BST不知道BSTNode是什么,解决方案是:
删除include并转发声明类,如下所示:
#pragma once
using namespace std;
class BSTNode; //Forward declare class so that BST knows BSTNode (move include to .cpp file)
class BST
{
private:
BSTNode* root;
public:
BST(void);
bool insert(int );
int search(int);
~BST(void);
};
主要功能示例:
int main( int argc, const char* argv[] )
{
printf( "nHello Worldnn" );
}
不带类型的"BSTNode"声明。在使用之前,您需要声明该类
相关文章:
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 错误 C2760:语法错误:映射迭代器上意外的标记"标识符",预期的";"
- 为什么我会收到错误 C2143 语法错误:缺少"*"之前的';'?
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 我该怎么做才能摆脱使用命名空间时的语法错误?
- 如何摆脱错误c2061;语法错误 cout?
- 语法错误:D3DX10Core 中的标识符'TEXTMETRICA'
- 错误 C2146:语法错误:标识符"A1"之前缺少","
- main.cpp(11):错误 C2059:语法错误:"字符串"
- RedisGraph 语法错误在偏移量 8 靠近"创建"
- 如何修复此 FSM C++语法错误 C3867
- 函数错误 C2059:语法错误:'>'不起作用
- 为什么在main()之前断言会导致语法错误"error: expected ')' before numeric constant"?
- c++default-int中的语法错误
- "pip install openexr"上的语法错误:错误的编译器?
- 为什么我收到语法错误:在"*"之前缺少";"
- 错误 C2059:语法错误:从结构成员声明'constant'
- C++语法错误,编译器不会警告或 int v = func(&v) 出错;
- 我正在调试这个C++程序.编译器不再显示语法错误,但存在隐藏的逻辑错误