本文介绍了Glut in Dev C ++ error“redeclaration of C ++ built-in type`short”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++的初学者。我使用Dev C ++作为我的IDE。我有这个简单的三角形绘图代码,它产生一个错误重新声明C ++内置类型短。但是当我在#include< glut.h> 之前放置#include< iostream.h>
谁能解释这背后的逻辑?

I am beginner to GLUT in C++. I am using Dev C++ as my IDE. I have this simple triangle drawing code and it produces an error "redeclaration of C++ built-in type short ". But When I put #include<iostream.h> before #include<glut.h>, it compiles and runs. Can anyone explain the logic behind that?

#include<glut.h>
void renderScene(void) {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
        glVertex3f(-0.5,-0.5,0.0);
        glVertex3f(0.5,0.0,0.0);
        glVertex3f(0.0,0.5,0.0);
    glEnd();

        glutSwapBuffers();
}

int main(int argc, char **argv) {

    // init GLUT and create Window
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(320,320);
    glutCreateWindow("My first program");

    // register callbacks
    glutDisplayFunc(renderScene);

    // enter GLUT event processing cycle
    glutMainLoop();

    return 1;
}


推荐答案

精确的glut.h和库版本,但我看到glut.h的回旋线45:

Hard to say without seeing your exact glut.h and library versions, but I see roundabout line 45 of glut.h:

   /* XXX This is from Win32's <ctype.h> */
#  ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#   define _WCHAR_T_DEFINED
#  endif

如果 wchar_t 已经定义(例如 short ),但是 _WCHAR_T_DEFINED 该行将被视为:

If wchar_t is already defined (to short for example), but the _WCHAR_T_DEFINED macro is not, the line will then be treated as:

typedef unsigned short short;

这是内建类型的重新声明。 < iostream> (不要使用.h btw,它不会被每个标准使用)是添加定义,使得typedef不执行,或undef'ing wchar_t 如果它是一个宏,使typedef是合法的。

Which is a redeclaration of the built-in type. <iostream> (don't use the .h btw, it's not used anymore per standard) is adding defines such that the typedef is not executed, or undef'ing wchar_t if it is a macro such that the typedef is legal.

这篇关于Glut in Dev C ++ error“redeclaration of C ++ built-in type`short”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 11:01