错误C2061:语法错误:标识符

时间:2013-03-30 06:54:01

标签: c++ syntax-error

这是我的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;
};

输出是:

“错误C2061:语法错误:标识符'BieuThucHang'”

如何解决?

1 个答案:

答案 0 :(得分:38)

您对头文件有循环依赖关系。您需要通过以下方式打破此循环包含依赖项 使用XuatChuoiBTHang.h中的转发声明:

class BieuThucHang;

另外,从#include "BieuThucHang.h"移除XuatChuoiBTHang.h