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

  • Home
  • SEARCH
  • 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 6241725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:49:12+00:00 2026-05-24T11:49:12+00:00

I have a struct called CardState defined in Application.h : #ifndef APPLICATION_H #define APPLICATION_H

  • 0

I have a struct called CardState defined in Application.h:

#ifndef APPLICATION_H
#define APPLICATION_H

#include <Session.h> // Note that both files include each others

struct CardState {
    bool property1;
    bool property2;
};

class Application : public QApplication {

    Q_OBJECT

public:

    explicit Application(int argc, char *argv[]);

}

I then use this CardState type in a different file:

#ifndef SESSION_H
#define SESSION_H

#include <Application.h>

struct CardState;

class Session : public QObject {

    Q_OBJECT

public:

    void setCardState(const CardState& cardState);
    CardState cardState() const;

private:

    CardState cardState_;

};

}
#endif // SESSION_H

At the time Session.h is included it seems that Application.h has not yet been included so I need to forward declare the struct (see above). However, this is not enough, after having added the forward declaration, I still get this error:

'Session::cardState_' uses undefined struct 'CardState'

Which, if I understand correctly, means that the compiler doesn’t know how to initialize my variable since CardState is only partially declared. I know I can fix this by making CardState a pointer, and that’s usually what I do, but is there any other, more proper way, to fix this?

  • 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-24T11:49:13+00:00Added an answer on May 24, 2026 at 11:49 am

    As per Oli Charlesworth’s comment, this should work as it is.

    In general case, you would want to either:

    • Put CardState in its own header and then #include it in all “client” headers, thus avoiding any complications that might arise from include order of these headers.
    • Declare Session::cardState_ as a (smart) pointer and avoid need for actual CardState declaration.

    — EDIT —

    Now that you edited the code, it is clear that there are circular include dependencies after all, in which case your code really isn’t going to work, so you must apply one of the solutions above.

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

Sidebar

Related Questions

I have a struct called Point (which happens to be a Python Extension) that
I have a struct called Point. Point is pretty simple: struct Point { Row
I have a struct called coordinate which is contained in a list in another
This is really a noob quick question. Imagine you have a struct called No
I am trying to model a network using C++. I have a struct called
I have a struct called CoolStruct: struct CoolStruct { int id; uint32 type; uint32
I have a header resource that I'm making use of that defines a struct
In Matlab, there is something called struct, which allow the user to have a
I have a class called CoolMenuItems class CoolMenuItems { public: CoolMenuItems(); ~CoolMenuItems(); struct MenuItemOne
So, one problem pattern that I keep coming across and don't have a good

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.