Help with part of code.

This is a discussion on Help with part of code. within the C++ Programming forums, part of the General Programming Boards category; Im currently debugging code for a game I'm writting and there is several errors I can't understand. I would post ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    21

    Help with part of code.

    Im currently debugging code for a game I'm writting and there is several errors I can't understand.

    I would post this is the game programming forum, but the errors seems to be centered around actually C++ coding errors so I thought here might be better.

    The first piece of code I'm getting errors with is:

    Code:
    // Change the speed of the saucer in response to arrow key presses
      if (GetAsyncKeyState(VK_LEFT) < 0)
        g_pCraftSprite->SetVelocity_x(--g_pCraftSprite->GetVelocity_x());
      else if (GetAsyncKeyState(VK_RIGHT) < 0)
        g_pCraftSprite->SetVelocity_x(++g_pCraftSprite->GetVelocity_x());
      if (GetAsyncKeyState(VK_UP) < 0)
        g_pCraftSprite->SetVelocity_y(--g_pCraftSprite->GetVelocity_y());
      else if (GetAsyncKeyState(VK_DOWN) < 0)
        g_pCraftSprite->SetVelocity_y(++g_pCraftSprite->GetVelocity_y());
    I get the following errors for all 4 key states:

    "spaceevade.cpp": E2096 Illegal structure operation in function HandleKeys() at line 274

    Any help understanding this error would be appreciated.

    My second error is in the code:

    Code:
    //Increase Velocity of asteriods
        for(i=0; i<9; i++)
         {
          g_pAsteriodSprite[i]->SetVelocity((g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)), 
    (g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)));
         }
    I get the following error:

    "spaceevade.cpp": E2094 'operator+' not implemented in type 'tagPOINT' for arguments of type 'int' in function EndLevel() at line 362


    Again I don't understand this problem.

    I've only posted the parts of the code with problems to save space, but if the rest is needed I can easily post this.

    Thanks in advance for any help.
    Last edited by ajdspud; 02-23-2006 at 02:39 PM.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    I'm not sure about the first error as I've never seen that function. AS for the second one, your error is right here:

    Code:
    g_pAsteriodSprite[i]->SetVelocity((g_pAsteriodSprite->GetVelocity_x() +=(g_iLevel*2))
    Unless that's an array of pointers, which I doubt it is, then you should be using a . operator not a -> operator.

    Change it to this and see what happens:

    Code:
    g_pAsteriodSprite[i].SetVelocity((g_pAsteriodSprite->GetVelocity_x() +=(g_iLevel*2))
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    21
    It is an array of pointers to Bitmap images i believe. Besides every other time I access a member function with g_pAsteriodSprite[i] it used the -> its just that part of code it doesnt like.

    As i stated in my post edit i changed that code to:

    Code:
    for(i=0; i<9; i++)
         {
          g_pAsteriodSprite[i]->SetVelocity((g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)), 
    (g_pAsteriodSprite[i]->GetVelocity_x() + (g_iLevel*2)));
         }
    and now i get a compltely different error.

    "spaceevade.cpp": E2094 'operator+' not implemented in type 'tagPOINT' for arguments of type 'int' in function EndLevel() at line 362


    If that changes things at all?

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Looks like you have to overload the + operator for the type tagPOINT.
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    21
    Problem fixed.

    My GetVelocity_x() function was declared as a POINT instead of an int, so the operators were not working.

    Thanks for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Skipping part of the code.
    By And3rs in forum C Programming
    Replies: 38
    Last Post: 10-01-2008, 02:52 PM
  2. Code writing issues Part 2...
    By jaybo684 in forum C++ Programming
    Replies: 10
    Last Post: 08-01-2005, 09:28 AM
  3. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 02:37 PM
  4. Replies: 4
    Last Post: 01-16-2002, 12:04 AM

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