Sign in to follow this  

Problem with classes

This topic is 4717 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 a class I use for double buffering, and I want to pass a pointer to an object of that class into a function but when I compile I get a massage saying that the class its not defined in that scope. here is the class (contained in gr_dbuffer.h): class cBuffer { public: // cBuffer (); //Initialize the buffer void Create (HWND); //So far fills the screen with the brush that is passed in void ClrScr (HBRUSH); //Sets the Background bitmap void SetBackGround (LPCSTR); //Resizes the buffer whenever the window size changes void Resize (); void Erase (RECT *); //Sends the contents of the back buffer to the front buffer, //in other words it prints whats in the back buffer void Swap (); //Displays a bitmap at the given coordinates in the BACK buffer void DisplayBitmap (HBITMAP, int x, int y); //Frees the memory used by the buffer void Free (); //Same as free :P ~cBuffer (); private: //Handle to the window HWND hwnd; //Client Rectangle RECT ScreenRect; //Handles used to display a bitmap HANDLE hCompBitmap; HANDLE hOldBitmap; HANDLE hOldBitmap2; //Handle to the Background bitmap HBITMAP hBackGround; //Buffer that represents the screen, everything sent //to it will be printed to the screen HDC FrontBuffer; //Buffer where everything is drawn before its sent //to the front buffer HDC BackBuffer; //HDC used to display bitmaps and stuff HDC SwapBuffer; }; And this is the function (in gam_menu.cpp): void InitMenu (cBuffer *buffer) { //Load the Bitmaps hBmStart = LoadBitmap ("Start.bmp"); hBmOptions = LoadBitmap ("Options.bmp"); hBmArrow = LoadBitmap ("Selector.bmp"); //Displays the Bitmaps buffer->DisplayBitmap (hBmStart, 310, 400); buffer->DisplayBitmap (hBmOptions, 310, 450); buffer->DisplayBitmap (hBmArrow, 268, 410); } And I call the function in the main file like this: InitMenu (&buffer); gr_dbuffer.h (the file with the double buffer class) is included in the header of the file that contains the function InitMenu, so I think they're in the same scope, but still I get this errors: variable or field InitMenu declared void 'cBuffer' was not declared in this scope expected primary-expresion before ')' token I'm using Dev-c++ 4.9.9.1 in win 98 Oh, and since its my first post here, Hello everyone!![smile]

Share this post


Link to post
Share on other sites
Yes, I did. The include thing is like this: main.h includes gam_menu.h (contains the function initmenu) and gam_menu includes gr_dbuffer.h (contains the double buffer class). The function initmenu is called from main.cpp.

Share this post


Link to post
Share on other sites
I don't use Dev-C++, so the messages are a little unusual to me, but it looks like the error is that the compiler doesn't recognise the identifier 'InitMenu' at the point where you're declaring it in the header.



variable or field InitMenu declared void

This error suggests that the compiler is trying to interpret the token 'InitMenu' as a new identifier being declared, but with no type given for the variable. This usually happens when you haven't #included the header with the function declaration in it, or when there's an error on the line previous to this statement.



'cBuffer' was not declared in this scope

It's possible that this is the token that failed, and that caused the previous error as the statement was not a valid function declaration. Otherwise, having failed to recognise the token 'InitMenu' as a function name, the compiler is moving on to parse the rest of the file, starting from the token directly after the error. It recognises 'cBuffer*' as a type, and thinks you're declaring a pointer to an instance of cBuffer, but it's reported an error because the class cBuffer is out of scope.



expected primary-expresion before ')' token

Now, having failed to parse the contents of the parentheses, it's trying to parse the closing parenthesis, but reporting a syntax error because you can't start a statement with a ')' character.


I'd guess that you're not including the relevant header(s) in whichever header InitMenu is declared in. From what you've said, it sounds like gr_dbuffer.h is not getting included properly in gam_menu.h. If you have it #included already, check and make sure you don't have some preprocessor problem (like an #ifdef that should be #ifndef) that's discarding the contents of your header.

Share this post


Link to post
Share on other sites

This topic is 4717 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