error C2061 - how to fix it?

my error: "error C2061: syntax error : identifier 'BieuThucHang' "
How to fix it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  // 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;
};

follow me at: https://blogger.com
Last edited on
There is a problem of circular includes:
XuatChuoiBTHang.h includes BieuThucHang.h and BieuThucHang.h includes XuatChuoiBTHang.h

Avoid it by just declaring the class in the header file.
In addition, you would also need to #include <string> and use the qualified name std::string
Note that the headers may be included (without problems) in the implementation (.cpp) files.

1
2
3
4
5
6
7
8
9
10
11
12
13
// XuatChuoiBTHang.h
#pragma once

// #include "BieuThucHang.h" // *** do not include the header  
class BieuThucHang ; // declare the class
#include <string> // *** required

class XuatChuoiBTHang
{
    public:
        // use BieuThucHang 'in name'
        virtual std::string xuatChuoi( BieuThucHang* btHang ) = 0;
};
Thank you JLBorges, i got it. Now, my code run well.
Topic archived. No new replies allowed.