RECT Beginner Problem

Started by
4 comments, last by GameDev.net 24 years, 6 months ago
Hmmm... that looks fine, and I tried compiling it and had no errors. Is there something before the RECT that may be causing the compiler to not translate it correctly?
Advertisement
It would help if you showed us your decleration of RECT.
My guess is that you arn't declaring the structure of RECT. It is part of the MFC headers in Visual C++, so if your project isn't including MFC, and you arn't explictly including any of the headers, then you will have to define it yourself. This isn't hard. The structure can be found in the help files:

typedef struct tagRECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;

RECT is defined in windef.h which is automatically included if you include windows.h. So if it's a Windows app, regardless of the flavor, RECT is defined. Since he said he included all the appropriate headers, I'm guessing that windows.h was one of them.

If it's not a Windows program,, of course RECT would have to be defined.

Here's what I've wrote :

RECT rect1 , rect2 , rect3 , rect4 , rect5 ;

line (21) rect1.left=4615;
rect1.top=3885;
rect1.right=28385;
rect1.bottom=12115;

And here what the Compiler says :
check.cpp(21) : error C2501: 'rect1' : Missing Declaration
check.cpp(21) : error C2371: 'rect1' : Newdefinition ; different Basis Types
check.cpp(21) : error C2239: Unexpected Token '.' after Declaration of 'rect1'
check.cpp(21) : error C2059: Syntax Error : '.'

I've included all important header files!

Ahhhh! Where is the code you gave us located? Is it outside of any function body? (I'm pretty sure it is). If so, that's your problem. You can declare a RECT (or any struct) globally, but you can't assign its members outside of a function body.

This topic is closed to new replies.

Advertisement