(c ++)在类中声明一个类成员

时间:2012-05-15 13:26:48

标签: c++ class declare

我正在尝试在每个CClient类中创建一个CBuffer成员,如下所示:

#ifndef CCLI_INC
#define CCLI_INC
#include "CBuffer.h"
#include "main.h"

    class CClient
    {
    private:

        CBuffer *m_buffer;


    public:
        CClient();



    };

但是这段代码给了我

 error C2143: syntax error : missing ';' before '*'
 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

虽然我已经包含了cbuffer.h标头,但是它给出了这个奇怪的错误..

1 个答案:

答案 0 :(得分:2)

转发声明CBuffer并丢失include

#ifndef CCLI_INC
#define CCLI_INC
#include "main.h"
class CBuffer;
class CClient
{
private:

    CBuffer *m_buffer;
public:
    CClient();
};