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

The Archive Base Latest Questions

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

I am implementing a card game. I want the window ui to be an

  • 0

I am implementing a card game. I want the window ui to be an object of class Rule, so that Rule can modify the GUI directly.

So Rule has an object Window * ui initialized in the constructor.

But during compilation, the compiler tells me that in rule.h, “Window has not been declared”, “Window is not a type”. I included <window.h>, everything has the same type, everything is initialized, so I run out of ideas of why it does not work.

EDIT: I edited the code following alexisdm’s notes. In addition, in rule.h, I had to change the definition of ui from Window * ui to Ui::Window *ui, because in window.h, ui is defined as Ui::Window * ui, and this is the object I want Rule::rule to control.

But now, in rule.cpp, ui->do_stuff() does not compile, because Ui::Window does not have the do_stuff() function, but Window does…

Arg! What to do?!! ui->do_stuff() works fine in window.cpp. Inheritance problem?

window.cpp:

    Window::Window(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Window)
{
    ui->setupUi(this);

    player = new Game_state();                  /* Game state                   */
    rule = new Rule(player, ui);                /* Implement the action of cards*/
}
void Window::do_stuff(){
//Do stuff
}

window.h

#include <QDialog>
#include "game_state.h"
#include "rule.h"

class Rule;
namespace Ui {
    class Window;
}

class Window : public QDialog
{
    Q_OBJECT

public:
    explicit Window(QWidget *parent = 0);
    ~Window();
    Game_state      * player;
    Rule            * rule;
    void do_stuff();

private:
    Ui::Window *ui;
};

rule.h

#ifndef RULE_H
#define RULE_H
#include "window.h"
#include <game_state.h>

class Window;

class Rule{
public:
    Rule(Game_state *, Ui::Window *);
    void action(Card *);

private:
    Game_state * player;
    Ui::Window     * ui;
};


#endif // RULE_H

rule.cpp

    #include <rule.h>

    Rule::Rule(Game_state * game, Ui::Window * window){
        player = game;
        ui = window;
    }
    void Rule::stuff(){
        ui->do_stuff();
    }
  • 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:48:54+00:00Added an answer on June 14, 2026 at 9:48 am

    There is a circular dependency in your headers: window.h and rule.h are referencing each other.

    You should replace both #include by forward declarations to avoid it.

    class Window;  // instead of #include "window.h"
    class Rule;  // instead of #include "rule.h"
    

    You’ll still need to add #include "window.h" in rule.cpp, and #include "rule.h" in window.cpp.

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

Sidebar

Related Questions

I am currently implementing a Deck class that represents a 52 card playing deck.
I'm implementing a card game. In this game I have a Board that is
I am implementing a card game, with a GUI, in C++, using Qt. I
I'm implementing a card game in C. There are lots of types of cards
In my web app,a customer object has fields related to credit card info public
I am implementing a flashcard game and I want to implement spaced repetition. I
Implementing a custom Dependency Property on a Framework Element object causes my Visual Studio
Implementing a custom membership provider, there are certain properties such as MinRequiredPasswordLength that only
I am working on a card game, as part of which I need to
I am currently implementing a credit card processing script, most as provided by the

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.