Jump to content
  • Advertisement
Sign in to follow this  
Dasil

My Class Is Not Recognized

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

Hi again, I'm creating my own rectangle class, and I'm having a problem: I've created a header, Rectangle.h, which contains the class Rectangle. The implementation file works and recognizes Rectangle. When I try to use the class in another cpp file, I get errors:
error C2146: syntax error : missing ';' before identifier 'rectangle'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2365: 'Rectangle' : redefinition; previous definition was 'function'
1>        c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(3667) : see declaration of 'Rectangle'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2228: left of '.create' must have class/struct/union
1>        type is 'int'
I've included Rectangle.h and I get these errors when I try to create a Rectangle object and use it.

Share this post


Link to post
Share on other sites
Advertisement
Wingdi.h has a Rectangle function:

__gdi_entry WINGDIAPI BOOL WINAPI Rectangle(__in HDC hdc, __in int left, __in int top, __in int right, __in int bottom);


So it looks like your program is getting this function confused with your class. Try changing the name, maybe something like CustomRectangle (or whatever).

Share this post


Link to post
Share on other sites
Thanks, that fixed it.

Is there a way that I can force the compiler to use my class (called Rectangle) instead of the Rectangle function? This way I wouldn't have to change the name, I don't mind changing it, I'm just curious.

Share this post


Link to post
Share on other sites
Yeah unfortunately windows puts all of it's stuff into the global namespace which often causes these kinds of problems (along with all of it's #defines...).

One solution is to put all of your own code into a namespace.
//myRectangle.h
namespace dasil {

class Rectangle
{
//...
};

}//end namespace dasil
//my cpp
#include "windows stuff"
#include "MyRectangle.h"

dasil::Rectangle r1;
//or
namespace dasil {
Rectangle r2;
}


Or you can screw around with windows like:
//my cpp
#define Rectangle DontUseTheName_Rectangle_PlzKThxBai
#include "windows stuff"
#undef Rectangle

#include "MyRectangle.h"

Rectangle r;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!