我想在头文件中转发声明一个结构。
struct GLFWvidmode;
class DesktopVideoMode {
private:
const GLFWvidmode *videomode;
public:
DesktopVideoMode(const GLFWvidmode *videomode);
...
在 cpp 文件中,我包含了带有定义的外部 header ...
#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;
我不能在这种情况下转发声明吗?
最佳答案
GLFWvidmode
不是结构,它是 typedef。您不能转发声明 typedef。选择使用未命名结构的人做出了糟糕的设计决定。
关于c++ - 结构前向声明错误 : Typedef redefinition with different types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18501993/