Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

objects with c++

Options
  • 01-12-2003 6:49pm
    #1
    Closed Accounts Posts: 222 ✭✭


    I think I'm trying to program in c++ and opengl ... but somehow I keep mixing java into it!! ... kinda like answering bits of your Irish leaving exam in English ... cause you couldn't think of the word.. and hope no one notices!!! ... compilers notice :ninja:

    what is wrong with this picture?

    c:\documents and settings\cp4027\cube\cuboid.h(15) : error C2059: syntax error : '{'
    c:\documents and settings\cp4027\cube\cuboid.h(15) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
    c:\documents and settings\cp4027\cube\cuboid.h(78) : error C2014: preprocessor command must start as first nonwhite space
    c:\documents and settings\cp4027\cube\cuboid.h(79) : fatal error C1070: mismatched #if/#endif pair in file 'c:\documents and settings\cp4027\cube\cuboid.h'
    Error executing cl.exe.

    cuboid.obj - 4 error(s), 0 warning(s)


    #include <windows.h>
    #include <gl\gl.h>
    #include <gl\glu.h>
    #include <gl\glaux.h>
    #ifndef CUBOID
    #define CUBOID

    class cuboid{
    public:

    cuboid(GLfloat x, GLfloat y, GLfloat z, GLuint cube_no);
    void draw_cuboid();
    /*static*/ GLfloat boxcol[27][6][3]=
    {
    /*1*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {1.0f,1.0f,0.0f}},
    /*2*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*3*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*4*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {1.0f,1.0f,0.0f}},
    /*5*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*6*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*7*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {1.0f,1.0f,0.0f}},
    /*8*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*9*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*10*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*11*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*12*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*13*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*14*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*15*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*16*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*17*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*18*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*19*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*20*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*21*/{{0.0f,1.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*22*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*23*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*24*/{{0.0f,1.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*25*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*26*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*27*/{{0.0f,1.0f,0.0f},{1.0f,1.0f,1.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}}
    };


    private:
    GLfloat x_, y_, z_;
    GLuint cube_no_;


    };#endif


Comments

  • Closed Accounts Posts: 25,848 ✭✭✭✭Zombrex


    Have you checked all your other header files ... sometimes when the compiler is having trouble at the very start of your header file it is because you have left out a ";" at the end of another header file


  • Closed Accounts Posts: 222 ✭✭The Second


    thats the only header file I have :confused:


  • Closed Accounts Posts: 222 ✭✭The Second


    the problem lies with the '{' ... is it ok to declare an array in the header file? ... will this array now be accessable to all the cube objects?

    /*static*/ GLfloat boxcol[27][6][3]=
    {
    /*1*/{{0.0f,0.0f


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    Just move the array outside the class but keep it inside cuboid.h, all the cube objects will still have access to it because you'll still be including that file.


  • Closed Accounts Posts: 222 ✭✭The Second


    I've done that now... but.....

    boxcol[cube_no_][num++] ... in cuboid.cpp is giving the error...

    error C2109: subscript requires array or pointer type... :confused:

    ... one other thing...

    cannot convert parameter 1 from 'float' to 'const float *'
    There is no context in which this conversion is possible....

    whats that all about???


  • Advertisement
  • Closed Accounts Posts: 222 ✭✭The Second


    k... problem re-worded!

    I am trying to make 27 cubes each with different colour orientation. I'm using openGL with it too. I have never used c++ before so I am kinda makin the code up as I go along! .... syntax is probably wrong somewhere... any help would be greatly appriciated cause I'm lost!

    this is the problem!

    : error C2078: too many initializers
    : error C2109: subscript requires array or pointer type
    : error C2664: 'glColor3fv' : cannot convert parameter 1 from 'float' to 'const float *'
    There is no context in which this conversion is possible

    I have this as my only header file:

    #ifndef CUBOID_H
    #define CUBOID_H

    #include <windows.h>
    #include <gl\gl.h>
    #include <gl\glu.h>
    #include <gl\glaux.h>

    class cuboid{
    private:
    GLfloat x_, y_, z_;
    GLuint cube_no_;

    public:

    cuboid(GLfloat x, GLfloat y, GLfloat z, GLuint cube_no);
    void draw_cuboid();
    };


    static GLfloat boxcol[]=
    {
    /*1*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {1.0f,1.0f,0.0f}},
    /*2*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*3*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*4*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {1.0f,1.0f,0.0f}},
    /*5*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*6*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*7*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {1.0f,1.0f,0.0f}},
    /*8*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*9*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,1.0f,1.0f},
    {0.0f,0.0f,0.0f}},
    /*10*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*11*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*12*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*13*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*14*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*15*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*16*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*17*/{{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*18*/{{0.0f,1.0f,0.0f},{0.0f,0.0f,0.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*19*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*20*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*21*/{{0.0f,1.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{1.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*22*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*23*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*24*/{{0.0f,1.0f,0.0f},{1.0f,1.0f,1.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*25*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {1.0f,1.0f,0.0f}},
    /*26*/{{0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}},
    /*27*/{{0.0f,1.0f,0.0f},{1.0f,1.0f,1.0f},{1.0f,0.5f,0.0f},{0.0f,0.0f,0.0f},{0.0f,0.0f,0.0f},
    {0.0f,0.0f,0.0f}}
    };



    #endif

    and this as the .cpp

    #include "cuboid.h"

    cuboid::cuboid(GLfloat x, GLfloat y, GLfloat z, GLuint cube_no){
    x_= x; y_= y; z_= z; cube_no_= cube_no;
    }

    void cuboid::draw_cuboid(){
    GLuint num=0;
    glBegin(GL_QUADS);
    //back
    glColor3fv(boxcol[cube_no_][num++]);
    glVertex3f( 1.0f,-1.0f,-1.0f);
    glVertex3f(-1.0f,-1.0f,-1.0f);
    glVertex3f(-1.0f, 1.0f,-1.0f);
    glVertex3f( 1.0f, 1.0f,-1.0f);
    //top
    glColor3fv(boxcol[cube_no_][num++]);
    glVertex3f( 1.0f, 1.0f,-1.0f);
    glVertex3f(-1.0f, 1.0f,-1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f( 1.0f, 1.0f, 1.0f);

    //left
    glColor3fv(boxcol[cube_no_][num++]);
    glVertex3f( 1.0f, 1.0f,-1.0f);
    glVertex3f( 1.0f, 1.0f, 1.0f);
    glVertex3f( 1.0f,-1.0f, 1.0f);
    glVertex3f( 1.0f,-1.0f,-1.0f);
    //right
    glColor3fv(boxcol[cube_no_][num++]);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f,-1.0f);
    glVertex3f(-1.0f,-1.0f,-1.0f);
    glVertex3f(-1.0f,-1.0f, 1.0f);
    //bottom
    glColor3fv(boxcol[cube_no_][num++]);
    glVertex3f( 1.0f,-1.0f, 1.0f);
    glVertex3f(-1.0f,-1.0f, 1.0f);
    glVertex3f(-1.0f,-1.0f,-1.0f);
    glVertex3f( 1.0f,-1.0f,-1.0f);
    //front
    glColor3fv(boxcol[cube_no_][num++]);
    glVertex3f( 1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f, 1.0f, 1.0f);
    glVertex3f(-1.0f,-1.0f, 1.0f);
    glVertex3f( 1.0f,-1.0f, 1.0f);

    glEnd();
    }


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    If you're initialising an array at the same time as declaring it you need to say how big it is. Change that line to static GLfloat boxcol[27][6][3]= like you had it in the first place. The rest of it looks fine.

    You could keep coming back here every time something fails to compile, but you'd probably be better off reading a java-to-C++ tutorial first, there's plenty of them out there (this one came up first in google). I'd also suggest you concentrate on C++ first, and once you're more comfortable with that (ie you at least understand pointers), then you can move on to OpenGL. Trying to bite off more than you can chew will probably just end up confusing you.


  • Closed Accounts Posts: 222 ✭✭The Second


    Sound thanks for that... I kinda have to byte off a fair bit though... tis for my Thesis! .... :eek: I'm screwed.


  • Closed Accounts Posts: 222 ✭✭The Second


    Jesus.. It worked!?!?!?!?!! A Jazz you are a gem... Thanks. :)


  • Registered Users Posts: 3,312 ✭✭✭mr_angry


    F*cking hell buddy - it took me a while to see that one myself, and I've done 4 years of C/C++! Arrays and pointers to them will cause endless problems.

    Just wait until you get all those errors about "differing levels of indirection"!

    ;)

    They're just out there waiting for you!


  • Advertisement
Advertisement