C ++中C结构的前向声明

时间:2012-05-29 11:15:35

标签: c++ c struct compatibility forward-declaration

  

可能重复:
  Forward declare FILE *

假设我想为C结构编写一个包装类,该结构由指向它的指针(如FILE

)加入 在C中你必须说

typedef struct _iobuf
    {
    /*content of this struct*/
    } FILE;

去除对象声明中的结构。现在我想在filec.h中执行以下操作:

class FILE;

class FileC
    {
    public:
        FileC(const char* name,const char* mode);
        ~FileC();
    private:
        FILE* fptr;
    };

在filec.cpp中:

#include "filec.h"
#include <cstdio>

//Implementation of FileC member functions

但是在编译时我只是抱怨不完整类型的struct FILE。切换包括命令,已经声明了FILE。我可以通过使用特定于实现的细节来解决它,或者使用void *来代替FILE *来回转换。但是怎么做得很好呢?使用iostream不是一个答案,因为它还包括stdio。

0 个答案:

没有答案
相关问题