Getting errors when compiling game with GCC. (error: changes meaning of ”Screen” from ”class Screen” [-fpermissive])

StackOverflow https://stackoverflow.com/questions/23400467

Question

Screen.h

#ifndef SCREEN_H
#define SCREEN_H

#include <SFML/Graphics.hpp>

class Screen
{
public:
    virtual void handleInput(sf::RenderWindow& window) = 0;
    virtual void update(sf::Time delta) = 0;
    virtual void render(sf::RenderWindow& window) = 0;

};

#endif

Game.h

#ifndef GAME_H
#define GAME_H

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

#include <vector>
#include <memory>

#include "Screen.h"

namespace sfSnake
{
class Game
{
public:
    Game();

    void run();

    void handleInput();
    void update(sf::Time delta);
    void render();

    static const int Width = 640;
    static const int Height = 480;

    static std::shared_ptr<Screen> Screen;
private:
    sf::RenderWindow window_;
    sf::Music bgMusic_;

    static const sf::Time TimePerFrame;
};
}


#endif

I have problems with these two headers. The code compiles fine with visual studio but won't with GCC.

I get the errors:

Description Resource    Path    Location    Type
error: changes meaning of ”Screen” from ”class Screen” [-fpermissive]   Screen.h    /Snake  line 6  C/C++ Problem

error: declaration of ”std::shared_ptr<Screen> sfSnake::Game::Screen” [-fpermissive]    Game.h  /Snake  line 28 C/C++ Problem

I have looked around for a while now and haven't found a solution. I really feel lost... Also this is not my code it was written by the user 'jh1997sa' on reddit. The source on github. His thread on reddit.

Était-ce utile?

La solution

You haven't named your platform, but I presume it's some flavor of Linux running X11. If so, this is most likely a name conflict with the Screen struct defined in X11/Xlib.h. SFML is almost certainly using Xlib behind the scenes to interact with the windowng system.

Because Xlib is a C library, all symbols it defines live in the global namespace. Fortunately in C++ you have the option of putting your Screen class in a namespace of your choosing. As long as you then refer to it by its fully qualified name, you can avoid the name clash.

Autres conseils

From what I understand, if you are trying to compile on a linux system you should be using g++ to compile instead of gcc.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top