【发布时间】:2013-08-29 03:52:18
【问题描述】:
我想在头文件中转发声明一个结构体。
struct GLFWvidmode;
class DesktopVideoMode {
private:
const GLFWvidmode *videomode;
public:
DesktopVideoMode(const GLFWvidmode *videomode);
...
在 cpp 文件中,我在定义中包含了外部标头...
#include "DesktopVideoMode.hpp"
#include <GLFW/glfw3.h>
...发生错误“Typedef redefinition with different types ('struct GLFWvidmode' vs 'GLFWvidmode')”:
typedef struct
{
/*! The width, in screen coordinates, of the video mode.
*/
int width;
/*! The height, in screen coordinates, of the video mode.
*/
int height;
/*! The bit depth of the red channel of the video mode.
*/
int redBits;
/*! The bit depth of the green channel of the video mode.
*/
int greenBits;
/*! The bit depth of the blue channel of the video mode.
*/
int blueBits;
/*! The refresh rate, in Hz, of the video mode.
*/
int refreshRate;
} GLFWvidmode;
在这种情况下我不能转发声明吗?
【问题讨论】:
-
是的,我意识到,在我发布评论并删除它之后。
-
@AdamS: 那么你不能避免包括标题...
标签: c++ struct forward-declaration