BlaCkOmN
BlaCkOmN

Reputation: 81

C++ issue : conflicting declaration

I have an issue on a C++ project with OpenGL : In my file 'cube.cpp' I have this :

    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 is an object which representing a vertex. Rails is an object which draw 3D rails. The issue is when I want to compile my project, I have this :

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];
           ^

I asked to my friends but we don't find why it doesn't want to compile rails(r), previously I had create a class Skybox and this class with the same type in argument works correctly.

If anyone have an idea...

Edit : rails.h

#ifndef RAILS_H_
#define RAILS_H_

#include "Struct.h"

using namespace std;

class rails{

public:

    rails(point3[]);

};
#endif /* RAILS_H_ */

And 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();
}

Upvotes: 0

Views: 388

Answers (1)

user934691
user934691

Reputation:

Currently, you are trying to create rails object named r.

Add a name of rails object to call the constructor. Like rails my(r);

Upvotes: 2

Related Questions