结构向前声明错误:使用不同类型重新定义Typedef [英] Struct forward declaration error: Typedef redefinition with different types

查看:81
本文介绍了结构向前声明错误:使用不同类型重新定义Typedef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在头文件中向前声明一个结构.

I want to forward declare a struct in the header file.

struct GLFWvidmode;

class DesktopVideoMode {
private:
    const GLFWvidmode *videomode;
public:
    DesktopVideoMode(const GLFWvidmode *videomode);
...

在cpp文件中,我包含带有定义的外部标头...

In the cpp file I include the external header with the definition...

#include "DesktopVideoMode.hpp"
#include <GLFW/glfw3.h>

...发生错误"使用不同类型('struct GLFWvidmode'与'GLFWvidmode')重新定义Typedef"

...where the error "Typedef redefinition with different types ('struct GLFWvidmode' vs 'GLFWvidmode')" happens:

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;

在这样的情况下我不能转发声明吗?

Can't I forward declare in a case like this?

推荐答案

GLFWvidmode 不是结构,而是typedef.您不能向前声明typedef.选择使用未命名结构的人会做出糟糕的设计决定.

GLFWvidmode is not a struct, it's a typedef. You can't forward-declare a typedef. Whoever chose to use an unnamed struct made a poor design decision.

这篇关于结构向前声明错误:使用不同类型重新定义Typedef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆