error C2061: syntax error : identifier

DungLe picture DungLe · Mar 30, 2013 · Viewed 64.4k times · Source

Here is my C++ code

// 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' "

How to fix it ?

Answer

Alok Save picture Alok Save · Mar 30, 2013

You have a circular dependency of header files. You need to break this circular inclusion dependency by using a forward declaration in XuatChuoiBTHang.h:

class BieuThucHang;

Also, remove #include "BieuThucHang.h" from XuatChuoiBTHang.h.