class member question...

This is a discussion on class member question... within the C++ Programming forums, part of the General Programming Boards category; First off, im using OpenGL...so, I have a function 'cube' that requests 4 parameters, an object name, x,y,and z values. ...

  1. #1
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428

    class member question...

    First off, im using OpenGL...so, I have a function 'cube' that requests 4 parameters, an object name, x,y,and z values. (cube(int objname,int x,int y, int z) Then I have a class that holds all of its coordinates...It works fine and dandy cept I cant get it to interpret the variable 'objname' as an actual number. So my class 'entity' ill do 'entity objname' 'objname.x=x....etc. But, obviously it reads 'objname' as the actual name, and not the variable stored in side. So, could I use a pointer somehow to get the value inside 'objname'? If not, what else should I try? thanks

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You are confused. objname is an int, thus, it can only hold numbers. Single quotes are usually used to form character literals (IE, only one character). I have no clue what goes on when you try to put multiple characters inside single quotes, but my guess is that it is undefined behavior.

    Essentally, you want to pass a char* or std::string to the cube function, and do so with double quotes rather than single quotes.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    thanks for the info, ill try it out.

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    > I have no clue what goes on when you try to put multiple characters inside single quotes, but my guess is that it is undefined behavior. <

    It interprets each character of the "string" as one byte of an integer.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    heres the function...:

    void pyramid(char objnum, int xtrans, int ytrans, int ztrans)
    {


    //start of problem
    entity1 objnum;
    objnum.transx=xtrans;
    objnum.transy=ytrans;
    objnum.transz=ztrans;
    //end of problem
    glTranslatef(xtrans,ytrans,ztrans);
    glBegin(GL_TRIANGLES); // Start Drawing The Pyramid

    glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)

    glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)

    glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)

    glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)

    glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)

    glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)



    glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)

    glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)

    glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)


    glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)

    glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)

    glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)
    glEnd(); // Done Drawing The Pyramid
    glLoadIdentity();

    }

  6. #6
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You can't create object names dynamically. You'll either have to store objnum within your class or create a class for each type using inheritance and virtual functions.

    Why do you need the objnum to be the name of your instance? Just create an array of instances and include an objnum member variable within your class as an identifier.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can Nested class access parent class's private member?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 06-05-2009, 08:42 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Replies: 6
    Last Post: 04-27-2006, 10:55 AM
  5. Yet another simple class question...
    By Ricochet in forum C++ Programming
    Replies: 3
    Last Post: 12-10-2003, 08:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21