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

Author Topic: Error: 'RenderWindow' in namespace 'sf' does not name a type.  (Read 1827 times)

0 Members and 1 Guest are viewing this topic.

Druidpeter

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Error: 'RenderWindow' in namespace 'sf' does not name a type.
« on: September 24, 2020, 05:18:32 pm »
So, I have game.hpp and game.cpp

Game.hpp:

#ifndef __GAME_HPP__
#define __GAME_HPP__

#include <list>
#include <string>
#include <mutex>

#include <SFML/Window.hpp>

namespace gm{
    // Bunch of class definitions, et al.
}

#endif


And here's game.cpp

#include <cstdlib>
#include <iostream>
#include <memory>
#include <thread>

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>

#include "game.hpp"

using namespace gm;

    // Bunch of class implementations and int main.


If I compile this code with g++ game.cpp -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -lsfml-network -lsfml-pthread it works absolutely fine, and I get a nice executable.

But now I have two other files: testCage.hpp and testCage.cpp.

testCage.hpp:

#ifndef __TEST_CAGE__
#define __TEST_CAGE__

#include <map>
#include <SFML/Window.hpp>
#include "game.hpp"

class TestEntity : public gm::Entity{
public:
    TestEntity():Entity(gm::EntityType::NULL_TYPE){};
    void testFoo(int m);
};

#endif


testCage.cpp:

#include "testCage.hpp"

void TestEntity::testFoo(int m){
    m += 1; // some garbage statement.
};


If I THEN try to compile and link both files with g++ game.cpp testCage.cpp -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -lsfml-network -lsfml-pthread

I get error: ‘RenderWindow’ in namespace ‘sf’ does not name a type in file included from testCage.hpp(e.g. game.hpp).

Even though testCage is just some test code, the architecture is worth mentioning. Everything in game.hpp is completely self-contained, and will never require any other locally developed header files. So, for example, game.hpp will never have a line like include "someCageHeader.hpp". Likewise, all cage headers should have ONLY "game.hpp" as their sole dependency, and will never include each other. Also likewise, all cage headers are perfectly self-contained in themselves, and the only file that mixes and matches calls to functions and classes defined in multiple different headers is in "game.cpp". This is the ONLY file that actually needs to include multiple cageHeader files.

Beyond that, I'm stumped. What's going on here? Any information that could help me figure out why trying to set things up this way is causing this error for me?

Thank you very much for your time.

fallahn

  • Sr. Member
  • ****
  • Posts: 492
  • Buns.
    • View Profile
    • Trederia
Re: Error: 'RenderWindow' in namespace 'sf' does not name a type.
« Reply #1 on: September 24, 2020, 05:50:55 pm »
Perhaps unintuitively RenderWindow is part of the graphics library rather than the window library - so you want to include <SFML/Graphics/RenderWindow.hpp> (or just Graphics.hpp if you prefer including everything) rather than <SFML/Window.hpp>

Druidpeter

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Error: 'RenderWindow' in namespace 'sf' does not name a type.
« Reply #2 on: September 24, 2020, 06:03:24 pm »
Fallahn!!!!!

Thank you so much!!! :D This was precisely the issue. :D

 

anything