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 6645055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:14:22+00:00 2026-05-26T00:14:22+00:00

In C++, I have a problem with a double include: File stuffcollection.h #pragma once

  • 0

In C++, I have a problem with a double include:

File stuffcollection.h

#pragma once
#ifndef STUFFCOLLECTION_H
#define STUFFCOLLECTION_H

#include "Stage.h"

class Stuffcollection {
    public:
        bool myfunc( Stage * stage );
};

#endif // STUFFCOLLECTION_H

File stage.h:

#pragma once
#ifndef STAGE_H
#define STAGE_H

#include "Stuffcollection.h"

class Stage {
    // stuffcollection used in stage.cpp
};

#endif // STAGE_H

Compiler Error:

\Stuffcollection.h|(line were bool myfunc is declared)|error: 'Stage' has not been declared|
||=== Build finished: 1 errors, 0 warnings ===|

Can someone please explain why this happens and how it can be solved? I already use include guards and the pragma once preprocessor directive and it just doesn’t work.

(If I remove #include "Stuffcollection.h" from stage.h and comment out the respective lines that are using it in stage.cpp, the rest of my code works fine. It’s really just when including Stuffcollection into stage that it suddenly stops working.)

PS: stage is just one example, I use stuffcollection in almost every other file too, and everytime I get this problem.

EDIT: I followed what has been suggested, and now the problem is invalid use of incomplete type, i.e. while the answers given solve the problem of the circular dependency they do not solve the problem I am dealing with. My problem is continued in Circular Dependencies / Incomplete Types.

EDIT: Both solved now.

  • 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-05-26T00:14:23+00:00Added an answer on May 26, 2026 at 12:14 am

    You have a Circular Dependency. Instead use Forward Declaration in Stuffcollection.h

    #pragma once
    #ifndef STUFFCOLLECTION_H
    #define STUFFCOLLECTION_H
    
    //#include "Stage.h"      //<------------------Don't Do This
    class Stage;              //<------------------Do This
    
    class Stuffcollection {
        public:
            bool myfunc( Stage * stage );
    };
    
    #endif // STUFFCOLLECTION_H
    

    Rationale:
    You can use the forward declaration in above snippet because, Stuffcollection.h only uses pointer to Stage.

    Explanation:
    Using a forward declaration of class Stage, the compiler does not know the composition of it nor the members inside it, the compiler only knows that Stage is a type. Thus,
    Stage is an Incomplete type for the compiler. With Incomplete types , One cannot create objects of it or do anything which needs the compiler to know the layout of Stage or more than the fact that Stage is just an type. Since pointers to all objects need just the same memory allocation, You can use the forward declaration when just referring to Stage as a pointer.

    You can use Forward Declarations to get over your circular dependency problems.

    Further Read:
    When to use forward Declarations?

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

Sidebar

Related Questions

I follow your suggests by now I have another problem. ifndef MARKERCONTAINE_H define MARKERCONTAINE_H
i have a problem with reading from a file, and converting content to double.
I have a problem with the mapping of Oracle Float double precision datatype to
I have a problem regarding 'static const' member initialization. In a templated class I
In a widely used include file in one of our projects we have these
I have written the following code: #include stdafx.h #include <iostream> using namespace std; double
I have some problem compiling my code. I have the following structure: #include <cstdlib>
I have complex model with double values...I have problem with pass them into object.
Possible Duplicate: Undefined reference to vtable I have a class Student on the file
I have problem in some JavaScript that I am writing where the Switch statement

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.