Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 'Window' in struct Shared_Context does not name a type  (Read 2835 times)

0 Members and 1 Guest are viewing this topic.

raybid

  • Newbie
  • *
  • Posts: 2
    • View Profile
'Window' in struct Shared_Context does not name a type
« on: January 13, 2021, 02:01:19 pm »
I was following the code in SFML Game Development by example, written by Order Nexus. I got hit by an errors in Shared Context. The code is as follows...
#include "Window.h"
#include "EventManager.h"

struct Shared_Context{
    Shared_Context():m_wind(nullptr),m_eventManager(nullptr) {}
    Window* m_wind;
    EventManager* m_eventManager;
};

The error appears is
include\SharedContext.h|8|error: 'Window' does not name a type|

My code for Window.h is as follows...
#ifndef WINDOW_H
#define WINDOW_H
#include <SFML/Window.hpp>
#include "EventManager.h"
#include "StateManager.h"


class Window
{
    public:
        Window();
        Window(const std::string& l_title,const sf::Vector2u& l_size);
        ~Window();

        void            BeginDraw(); // Clear the window.
        void            EndDraw(); // Display the changes.
        void            Update();
        bool            IsDone();
        bool            IsFullscreen();
        sf::Vector2u    GetWindowSize();
        //void ToggleFullscreen();
        void            Draw(sf::Drawable& l_drawable);
        bool            IsFocused();
        EventManager*   GetEventManager();
        void            Close(/*EventDetails* l_details = nullptr*/);

    protected:

    private:
        void                Setup(const std::string l_title, const sf::Vector2u& l_size);
        void                Destroy();
        void                Create();
        sf::RenderWindow    m_window;
        sf::Vector2u        m_windowSize;
        std::string         m_windowTitle;
        bool                m_isDone;
        bool                m_isFullscreen;
        EventManager        m_eventManager;
};

#endif // WINDOW_H
 

I hope someone can help me and explains why do I get this error  :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 'Window' in struct Shared_Context does not name a type
« Reply #1 on: January 13, 2021, 04:05:11 pm »
The code looks ok. Maybe a loop in includes? What headers do EnventManager.h and StateManager.h include?
Laurent Gomila - SFML developer

raybid

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: 'Window' in struct Shared_Context does not name a type
« Reply #2 on: January 13, 2021, 05:15:33 pm »
The code looks ok. Maybe a loop in includes? What headers do EnventManager.h and StateManager.h include?

The EventManager.h include this
#include <unordered_map>
#include <functional>
#include <SFML/Graphics.hpp>
#include "CustomHash.h"
#include <fstream>
#include <sstream>

The StateManager.h include this
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <unordered_map>
#include <functional>
#include "Window.h"
#include "EventManager.h"
#include "CustomHash.h"
#include "SharedContext.h"


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 'Window' in struct Shared_Context does not name a type
« Reply #3 on: January 13, 2021, 08:19:03 pm »
So, yes, you have headers that include each other. That doesn't work. #include statements are not always needed, a forward declaration is often enough.
Laurent Gomila - SFML developer