C++ 错误 C2061:语法错误:标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15715882/
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
error C2061: syntax error : identifier
提问by DungLe
Here is my C++ code
这是我的 C++ 代码
// XuatChuoiBTHang.h
#pragma once
#include "BieuThuc.h"
#include "BieuThucHang.h"
class XuatChuoiBTHang
{
public:
virtual string xuatChuoi(BieuThucHang* btHang) = 0;
};
// BieuThucHang.h
#pragma once
#include "bieuthuc.h"
#include "XuatChuoiBTHang.h"
class BieuThucHang : public BieuThuc
{
private:
XuatChuoiBTHang* xuatChuoiBTHang;
};
Ouput is:
输出为:
"error C2061: syntax error : identifier 'BieuThucHang' "
“错误 C2061:语法错误:标识符 'BieuThucHang'”
How to fix it ?
如何解决?
回答by Alok Save
You have a circular dependency of header files. You need to break this circular inclusion dependency by
using a forward declaration in XuatChuoiBTHang.h
:
你有头文件的循环依赖。您需要通过在 中使用前向声明来打破这种循环包含依赖XuatChuoiBTHang.h
:
class BieuThucHang;
Also, remove #include "BieuThucHang.h"
from XuatChuoiBTHang.h
.
此外,#include "BieuThucHang.h"
从XuatChuoiBTHang.h
.