Sign in to follow this  

error on prototyping class function

This topic is 2535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have 2 button class first class is for menu and second is for in game menu but when i'm finishing second class for in game i can't prototype handle event() and i can't figure out why.

using dev c++ for compiling and i'm making menu with SDL


class ButtonInGame
{
private:
SDL_Rect boxfire;
SDL_Rect boxiced;
SDL_Rect boxlase;

SDL_Rect* Rfire;
SDL_Rect* Riced;
SDL_Rect* Rlase;

int ffire , ficed , flase;

public:
ButtonInGame()
{
//Set the button's attributes
boxfire.x = 690;
boxfire.y = 334;
boxfire.w = 320;
boxfire.h = 60;

boxiced.x = 690;
boxiced.y = 394;
boxiced.w = 320;
boxiced.h = 60;

boxlase.x = 690;
boxlase.y = 454;
boxlase.w = 320;
boxlase.h = 60;

//Set the default sprite
Rfire = &RFire[ CLIP_MOUSEOUT ];
Riced = &RIced[ CLIP_MOUSEOUT ];
Rlase = &RLase[ CLIP_MOUSEOUT ];

ffire = 0 , ficed = 0 , flase = 0 ; //flag mouse over ;0 belum bunyi 1 s
}
void handle_event();

//Shows the button on the screen
void show();

void FireClick();

void IcedClick();

void LaseClick();

//void HelpClick();
}

void ButtonInGame::handle_event()
{
//The mouse offsets
int x = 0, y = 0;
//If the mouse moved
if( event.type == SDL_MOUSEMOTION )
{
//Get the mouse offsets
x = event.motion.x;
y = event.motion.y;

//If the mouse is over the button
if( ( x > boxfire.x ) && ( x < boxfire.x + boxfire.w ) && ( y > boxfire.y ) && ( y < boxfire.y + boxfire.h ) )
{
//Set the button sprite

Rfire = &RFire[ CLIP_MOUSEOVER ];
//Set the button sprite
Riced = &RIced[ CLIP_MOUSEOUT ];
Rlase = &RLase[ CLIP_MOUSEOUT ];
if(ffire == 0)
{Mix_PlayChannel( -1, over, 0 );
ffire =1 ; ficed = 0; flase = 0;
}


// _sleep(600);
//Play the scratch effect

}
else if( ( x > boxiced.x ) && ( x < boxiced.x + boxiced.w ) && ( y > boxiced.y ) && ( y < boxiced.y + boxiced.h ) )
{
//Set the button sprite
Riced = &RIced[ CLIP_MOUSEOVER ];
//Set the button sprite
Rfire = &RFire[ CLIP_MOUSEOUT ];
Rlase = &RLase[ CLIP_MOUSEOUT ];

if(ficed == 0)
{Mix_PlayChannel( -1, over, 0 );
ffire =0; ficed = 1; flase = 0 ;
}
// _sleep(600);

//Play the scratch effect

}
else if( ( x > boxlase.x ) && ( x < boxlase.x + boxlase.w ) && ( y > boxlase.y ) && ( y < boxlase.y + boxlase.h ) )
{
//Set the button sprite
Rlase = &RLase[ CLIP_MOUSEOVER ];
//Set the button sprite
Rfire = &RFire[ CLIP_MOUSEOUT ];
Riced = &RIced[ CLIP_MOUSEOUT ];

if(flase == 0)
{Mix_PlayChannel( -1, over, 0 );
ffire =0; ficed = 0; flase = 1 ;
}
// _sleep(600);

//Play the scratch effect

}
}

//If not
else
{
//Set the button sprite
Rfire = &RFire[ CLIP_MOUSEOUT ];
Riced = &RIced[ CLIP_MOUSEOUT ];
Rlase = &RLase[ CLIP_MOUSEOUT ];

ffire =0; ficed = 0; flase = 0 ;
}

//If a mouse button was pressed

//If a mouse button was released
if( event.type == SDL_MOUSEBUTTONUP )
{
//If the left mouse button was released
if( event.button.button == SDL_BUTTON_LEFT )
{
//Get the mouse offsets
x = event.button.x;
y = event.button.y;

//If the mouse is over the button
if( ( x > boxfire.x ) && ( x < boxfire.x + boxfire.w ) && ( y > boxfire.y ) && ( y < boxfire.y + boxfire.h ) )
{
//if(Tower.gold >= Api.cost)
FireClick();
//Set the button sprite
//Rfire = &RFire[ CLIP_MOUSEUP ];
}
else if( ( x > boxiced.x ) && ( x < boxiced.x + boxiced.w ) && ( y > boxiced.y ) && ( y < boxiced.y + boxiced.h ) )
{
//if(Tower.gold >= Aer.cost)
IcedClick();
//Set the button sprite
//Rfire = &RFire[ CLIP_MOUSEUP ];
}
else if( ( x > boxlase.x ) && ( x < boxlase.x + boxlase.w ) && ( y > boxlase.y ) && ( y < boxlase.y + boxlase.h ) )
{
//if(Tower.gold >= Laser.cost)
LaseClick();
//Set the button sprite
//Rhelp = &RHelp[ CLIP_MOUSEUP ];
//helpstate.showhelp();
}
}
}
}



Share this post


Link to post
Share on other sites
Quote:
Original post by ShyAngel
lol thanks i didn't notice it


Don't worry, this is an incredibly common error when you are relatively new and a consequence of one of the many peculiarities of C++.

It's because you can define objects immediately after the class definition:

class A
{
} a;

// equivalent to

class A
{
};

A a;


Hope this helps to understand why the pesky little semi is so important.

Share this post


Link to post
Share on other sites
Quote:
Original post by assainator
May I suggest moving to a newer IDE like Visual Studio Express or Code::Blocks?
There are a lot of reasons why you shouldn't use dev c++.

assainator


thanks for your concern :), i do want change to VS but some problem are holding me like i get plenty of "unexplained" error and other stuff :P,
like this it's simple program to calculate rectangular capacity


// rect.cpp : main project file.
#include <iostream>
#include <conio2.h>

using namespace std;

int main()
{
int pj=0, lbr=0, hasil=0;
clrscr();
cout<<"=-=- PROGRAM MENGHITUNG LUAS PERSEGI PANJANG -=-="<<endl;
cout<<"PANJANG (P) = "; cin>>pj;
cout<<"LEBAR (L) = "; cin>>lbr;
hasil = pj * lbr;
cout<<"\nLUAS PERSEGI PANJANG (P*L) = "<<hasil;
getch();
return 0;

}



and the errors are


Warning 1 warning C4103: 'c:\program files\microsoft visual studio 10.0\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop) C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winnt.h 3035 1 rect
Warning 2 warning C4103: 'c:\program files\microsoft visual studio 10.0\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop) C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winnt.h 3327 1 rect
Warning 3 warning C4068: unknown pragma C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winnt.h 3423 1 rect
Warning 4 warning C4068: unknown pragma C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winnt.h 3428 1 rect
Error 5 error C2144: syntax error : 'void' should be preceded by ';' C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1252 1 rect
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1252 1 rect
Error 7 error C2144: syntax error : 'void' should be preceded by ';' C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1253 1 rect
Error 8 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1253 1 rect
Error 9 error C2086: 'int DECLSPEC_NORETURN' : redefinition C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1253 1 rect
Error 10 error C2144: syntax error : 'void' should be preceded by ';' C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1313 1 rect
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1313 1 rect
Error 12 error C2086: 'int DECLSPEC_NORETURN' : redefinition C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winbase.h 1313 1 rect
Error 13 error C2144: syntax error : 'void' should be preceded by ';' C:\Program Files\Microsoft Visual Studio 10.0\VC\include\rpcdce.h 366 1 rect
Error 14 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\rpcdce.h 366 1 rect
Error 15 error C2086: 'int DECLSPEC_NORETURN' : redefinition C:\Program Files\Microsoft Visual Studio 10.0\VC\include\rpcdce.h 366 1 rect
Error 16 error C3646: 'I_RpcAllocate' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\rpcdcep.h 89 1 rect
Error 17 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\rpcdcep.h 89 1 rect
Error 18 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\rpcdcep.h 89 1 rect
Warning 19 warning C4103: 'c:\program files\microsoft visual studio 10.0\vc\include\shellapi.h' : alignment changed after including header, may be due to missing #pragma pack(pop) C:\Program Files\Microsoft Visual Studio 10.0\VC\include\shellapi.h 129 1 rect
Warning 20 warning C4103: 'c:\program files\microsoft visual studio 10.0\vc\include\shellapi.h' : alignment changed after including header, may be due to missing #pragma pack(pop) C:\Program Files\Microsoft Visual Studio 10.0\VC\include\shellapi.h 265 1 rect
Error 21 error C3646: 'inet_ntoa' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 524 1 rect
Error 22 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 524 1 rect
Error 23 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 524 1 rect
Error 24 error C2733: second C linkage of overloaded function 'DECLARE_STDCALL_P' not allowed C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 524 1 rect
Error 25 error C3646: 'gethostbyaddr' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 533 1 rect
Error 26 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 533 1 rect
Error 27 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 533 1 rect
Error 28 error C2733: second C linkage of overloaded function 'DECLARE_STDCALL_P' not allowed C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 533 1 rect
Error 29 error C3646: 'gethostbyname' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 534 1 rect
Error 30 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 534 1 rect
Error 31 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 534 1 rect
Error 32 error C2556: 'int (__cdecl *DECLARE_STDCALL_P(hostent *))(const char *)' : overloaded function differs only by return type from 'int (__cdecl *DECLARE_STDCALL_P(hostent *))(const char *,int,int)' C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 534 1 rect
Error 33 error C2371: 'DECLARE_STDCALL_P' : redefinition; different basic types C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 534 1 rect
Error 34 error C3646: 'getservbyport' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 535 1 rect
Error 35 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 535 1 rect
Error 36 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 535 1 rect
Error 37 error C2733: second C linkage of overloaded function 'DECLARE_STDCALL_P' not allowed C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 535 1 rect
Error 38 error C3646: 'getservbyname' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 536 1 rect
Error 39 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 536 1 rect
Error 40 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 536 1 rect
Error 41 error C2556: 'int (__cdecl *DECLARE_STDCALL_P(servent *))(const char *,const char *)' : overloaded function differs only by return type from 'int (__cdecl *DECLARE_STDCALL_P(servent *))(int,const char *)' C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 536 1 rect
Error 42 error C2371: 'DECLARE_STDCALL_P' : redefinition; different basic types C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 536 1 rect
Error 43 error C3646: 'getprotobynumber' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 537 1 rect
Error 44 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 537 1 rect
Error 45 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 537 1 rect
Error 46 error C2733: second C linkage of overloaded function 'DECLARE_STDCALL_P' not allowed C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 537 1 rect
Error 47 error C3646: 'getprotobyname' : unknown override specifier C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 538 1 rect
Error 48 error C2091: function returns function C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 538 1 rect
Error 49 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 538 1 rect
Error 50 error C2556: 'int (__cdecl *DECLARE_STDCALL_P(protoent *))(const char *)' : overloaded function differs only by return type from 'int (__cdecl *DECLARE_STDCALL_P(protoent *))(int)' C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 538 1 rect
Error 51 error C2371: 'DECLARE_STDCALL_P' : redefinition; different basic types C:\Program Files\Microsoft Visual Studio 10.0\VC\include\winsock2.h 538 1 rect



Share this post


Link to post
Share on other sites
That looks like a b0rked installation, or a hard drive going bad.

I've had a similar problem occur recently. Plenty of error messages seemingly generated from Visual Studio header files. When the files in question were examined, it turned out that parts of them had been corrupted, causing all kinds of mayhem. I had to completely uninstall and then reinstall it. (And still need to get the hard drive replaced...)

Share this post


Link to post
Share on other sites

This topic is 2535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this