Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:46:24+00:00 2026-06-14T09:46:24+00:00

Consider this class from the WinAPI: typedef struct tagRECT { LONG left; LONG top;

  • 0

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 Rects, 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:46:25+00:00Added an answer on June 14, 2026 at 9:46 am

    You doesn’t need to know the function definition before actually dereferencing the type.

    So you can forward declare in your header file (because you will not make any dereferencing here) then include Windows.h in your source file.

    [edit] Didn’t seen that it was a typedef. However, the other answer is wrong : there is a way to (kind of) forward declare a typedef.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this simple class that demonstrates RAII in C++ (From the top of my
Consider this - a base class A, class B inheriting from A, class C
Consider this code from the official OpenJDK source of java.awt.font.TextLayout : public final class
Consider this hypothetical implementation of vector : template<class T> // ignore the allocator struct
Consider this small piece of code from apscheduler.scheduler import Scheduler import time class First():
Consider this class hierarchy: Book extends Goods Book implements Taxable As we know, there
Consider this: class User < ActiveRecord::Base # name, email, password end class Article <
Consider this class: class test { public function __set($n, $v) { echo __set() called\n;
Consider this sample class, class TargetClass { private static String SENSITIVE_DATA = sw0rdfish; private
Consider this code : class MyClass<T> { } class AnotherClass : MyClass<String> { }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.