views:

59

answers:

2

ok so i nee help with this constructures

struct balls {
         balls()
         {
                SetTimer(hWnd, balls.BALL_ID, 1, null);
         }
    int Ex;
    int Ey;
    UINT_PTR BALL_ID;
};

well when i set the timer im having trouble with balls.BALL_ID. the compiler thinks that balls is structure like balls something. well i want ball to have the value of the structure. like this

         balls()
         {
                SetTimer(hWnd, balls.BALL_ID, 1, null);
         }
    int Ex;
    int Ey;
    UINT_PTR BALL_ID;
};
balls something;

now it creates the structure with something.BALL_ID instead of balls.BALL_ID. in balls() that wat it do it changes balls() to something(). any idea how to change the balls.BALL_ID to stuctureName.BALL_ID?

A: 

balls.BALL_ID requries 'ball' to be an object expression. Here 'balls' is a class. So the code is ill-formed.

$5.2.5/2 states- "For the first option (dot) the type of the first expression (the object expression) shall be “class object” (of a complete type)."

So, your call could be

SetTimer(hWnd, BALL_ID, 1, null);

Also, please initialize all the class members in the constructor before using them.

Chubsdad
+1  A: 

BALL_ID is a member of the balls struct so when you want to use it within a member function you don't need to prefix it with the name of an instance. So just initialize BALL_ID then use it:

struct balls {
         balls( UINT_PTR id ) : BALL_ID( id ), Ex( 0 ), Ey( 0 )
         {
                SetTimer(hWnd, BALL_ID, 1, NULL);
         }
    int Ex;
    int Ey;
    UINT_PTR BALL_ID;
};

balls something( IDT_TIMER1 );
Eugen Constantin Dinca
Note that hWnd must be accessible too.
Anthony Williams
@Anthony: that's exactly right, I've slightly assumed hWnd to be a global variable... (and just realized I wrote `null` instead of `NULL`).
Eugen Constantin Dinca