Results 1 to 4 of 4

Thread: Error w/ 'struct' using Dev-C++

  1. #1

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157

    Error w/ 'struct' using Dev-C++

    Hi,
    I have added a structure to my code. I tried initializing variables and kept getting an error citing a syntax error before '.'

    Here is a code fragment...

    Code:
    struct gameObject
    {
      float x; //current position
      float y;
      float z;
    };
    
    gameObject cam;
    cam.x=0;
    The error points to line that reads cam.x=0;

    Any clues? Do I need a specific header?

    Regards,
    ChuckB

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Hmm, odd. Try this:
    Code:
    struct gameObject cam;
    cam.x = 0;
    That is C style structure variable declaration.

    Z.

  3. #3

    Thread Starter
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    Thanks for writing Z,

    The structure was correct. However, C++ doesn't like 'cam.x=0;' to go above all of the functions. I placed the initialization inside a initVars() function and it worked well...learning curve. :-)

    In fact, I got rid of the structure and made my first official C++ class CGameObject with about a dozen variables and a dozen functions to manage my robots on the game field.

    Regards,
    ChuckB

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Ah, ok. I hadnt realized that the assignment wasnt in a function =).

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width