我在使用OpenGL的C ++项目中遇到了一个问题: 在我的文件' cube.cpp'我有这个:
point3 r1 = point3(40.0,0.0,-450.0);
point3 r2 = point3(55.0,0.0,-450.0);
point3 r3 = point3(55.0,0.5,-450.0);
point3 r4 = point3(40.0,0.5,-450.0);
point3 r[4];
r[0] = r1;
r[1] = r2;
r[2] = r3;
r[3] = r4;
rails(r);
Point3是表示顶点的对象。 Rails是绘制3D轨道的对象。 问题是,当我想编译我的项目时,我有这个:
g++ Struct.cpp skybox.cpp rails.cpp cube.cpp -o train
cube.cpp:
In function ‘void display()’:
cube.cpp:296:11: error: conflicting declaration ‘rails r’
rails(r);
^
cube.cpp:291:11: error: ‘r’ has a previous declaration as ‘point3 r [4]’
point3 r[4];
^
我问过我的朋友,但我们不知道为什么它不想编译rails(r),之前我创建了一个类Skybox,这个类在参数中的类型正常工作。
如果有人有想法......
编辑: rails.h
#ifndef RAILS_H_
#define RAILS_H_
#include "Struct.h"
using namespace std;
class rails{
public:
rails(point3[]);
};
#endif /* RAILS_H_ */
和rails.cpp
#include "rails.h"
#ifdef __APPLE__
//compilation sous MacOs par :
//gcc -framework GLUT -framework OpenGL -framework Cocoa source.c -o nom_executable
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#endif
#ifdef __WIN32__
//parce qu'il manque des choses aux gens qui utilisent MsWindows, où OpenGL ne peut fonctionner que s'il discute avec le gestionnaire de fenêtres ("windows.h")
#define GLUT_DISABLE_ATEXIT_HACK //utile si vous compilez en g++ sous windows avec le glut.lib prévu pour MsVisual
#include <windows.h>
#include "glut.h" //il faut avoir le fichier "glut.h" dans le même répertoire que votre .cpp (et aussi le glut.lib et le glut.dll)
#endif
#ifdef __linux__
//pour les non-windowiens, GLUT (fenêtrage opengl) est inclu dans les distributions
//pour les ubuntiens : apt-get install freeglut3 freeglut3-dev
#include <GL/glut.h>
#include <GL/glu.h>
#endif
rails::rails(point3 rd[]){
float dis = 0.0;
while(dis < 900){
glBegin(GL_QUADS);
glColor3ub(90,0,0);
glVertex3d(rd[0].x,rd[0].y,rd[0].z+dis);
glVertex3d(rd[1].x,rd[1].y,rd[1].z+dis);
glVertex3d(rd[2].x,rd[2].y,rd[2].z+dis);
glVertex3d(rd[3].x,rd[3].y,rd[3].z+dis);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,0,0);
glVertex3d(rd[0].x,rd[0].y,rd[0].z+2.0+dis);
glVertex3d(rd[1].x,rd[1].y,rd[1].z+2.0+dis);
glVertex3d(rd[2].x,rd[2].y,rd[2].z+2.0+dis);
glVertex3d(rd[3].x,rd[3].y,rd[3].z+2.0+dis);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,0,0);
glVertex3d(rd[3].x,rd[3].y,rd[3].z+dis);
glVertex3d(rd[2].x,rd[2].y,rd[2].z+dis);
glVertex3d(rd[2].x,rd[2].y,rd[2].z+2.0+dis);
glVertex3d(rd[3].x,rd[3].y,rd[3].z+2.0+dis);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,0,0);
glVertex3d(rd[0].x,rd[0].y,rd[0].z+dis);
glVertex3d(rd[3].x,rd[3].y,rd[3].z+dis);
glVertex3d(rd[3].x,rd[3].y,rd[3].z+2.0+dis);
glVertex3d(rd[0].x,rd[0].y,rd[0].z+2.0+dis);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,0,0);
glVertex3d(rd[1].x,rd[1].y,rd[1].z+dis);
glVertex3d(rd[2].x,rd[2].y,rd[2].z+dis);
glVertex3d(rd[2].x,rd[2].y,rd[2].z+2.0+dis);
glVertex3d(rd[1].x,rd[1].y,rd[1].z+2.0+dis);
glEnd();
dis=dis+5.0;
}
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(54.0,0.0,-450.0);
glVertex3d(53.5,0.0,-450.0);
glVertex3d(53.5,1.0,-450.0);
glVertex3d(54.0,1.0,-450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(54.0,0.0,450.0);
glVertex3d(53.5,0.0,450.0);
glVertex3d(53.5,1.0,450.0);
glVertex3d(54.0,1.0,450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(54.0,1.0,-450.0);
glVertex3d(53.5,1.0,-450.0);
glVertex3d(53.5,1.0,450.0);
glVertex3d(54.0,1.0,450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(54.0,0.0,-450.0);
glVertex3d(54.0,1.0,-450.0);
glVertex3d(54.0,1.0,450.0);
glVertex3d(54.0,0.0,450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(53.5,0.0,-450.0);
glVertex3d(53.5,1.0,-450.0);
glVertex3d(53.5,1.0,450.0);
glVertex3d(53.5,0.0,450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(41.0,0.0,-450.0);
glVertex3d(41.5,0.0,-450.0);
glVertex3d(41.5,1.0,-450.0);
glVertex3d(41.0,1.0,-450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(41.0,0.0,450.0);
glVertex3d(41.5,0.0,450.0);
glVertex3d(41.5,1.0,450.0);
glVertex3d(41.0,1.0,450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(41.0,1.0,-450.0);
glVertex3d(41.5,1.0,-450.0);
glVertex3d(41.5,1.0,450.0);
glVertex3d(41.0,1.0,450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(41.0,0.0,-450.0);
glVertex3d(41.0,1.0,-450.0);
glVertex3d(41.0,1.0,450.0);
glVertex3d(41.0,0.0,450.0);
glEnd();
glBegin(GL_QUADS);
glColor3ub(90,90,90);
glVertex3d(41.5,0.0,-450.0);
glVertex3d(41.5,1.0,-450.0);
glVertex3d(41.5,1.0,450.0);
glVertex3d(41.5,0.0,450.0);
glEnd();
}
答案 0 :(得分:2)
目前,您正在尝试创建名为rails
的<{1}}对象。
添加r
对象的名称以调用构造函数。与rails