Consider this class from the WinAPI:
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;
I am enhancing it in a class named Rect
which allows you to multiply/add/subtract/compare two Rect
s, along with other features. The only real reason I need my Rect
class to know about RECT
is because the class features a conversion operator that allows a Rect
to be passed as a RECT
, and to be assigned a RECT
.
But, in the file Rect.h
, I do not want to include <Windows.h>
, I only want to include <Windows.h>
in the source file so that I may keep my inclusion tree small.
I know that structures can be forward declared like so: struct MyStruct;
But, the actual name of the structure is tagRECT
and it has an object list, so I am kind of confused as to how to forward declare it. Here is a portion of my class:
// Forward declare RECT here.
class Rect {
public:
int X, Y, Width, Height;
Rect(void);
Rect(int x, int y, int w, int h);
Rect(const RECT& rc);
//! RECT to Rect assignment.
Rect& operator = (const RECT& other);
//! Rect to RECT conversion.
operator RECT() const;
/* ------------ Comparison Operators ------------ */
Rect& operator < (const Rect& other);
Rect& operator > (const Rect& other);
Rect& operator <= (const Rect& other);
Rect& operator >= (const Rect& other);
Rect& operator == (const Rect& other);
Rect& operator != (const Rect& other);
};
Would this be valid?
// Forward declaration
struct RECT;
My thought is no, since RECT
is just an alias of tagRECT
. I mean, I know the header file would still be valid if I did this, but when I create the source file Rect.cpp
and include <Windows.h>
there, I fear that is where I am going to experience problems.
How could I forward declare RECT
?