• 12
• 12
• 9
• 10
• 13

# My Class Is Not Recognized

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

## 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 on other sites
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 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 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.hnamespace dasil {class Rectangle{//...};}//end namespace dasil
//my cpp#include "windows stuff"#include "MyRectangle.h"dasil::Rectangle r1;//ornamespace 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;