SFML community forums

Help => General => Topic started by: Forceofaqua on July 22, 2015, 07:26:10 pm

Title: C++ class redefinition and undefined using screen management
Post by: Forceofaqua on July 22, 2015, 07:26:10 pm
I'm having an odd error pop up, and cant seem to figure out why its happening. I'm using code to help me manage screens within my application. The code I am using is found here https://github.com/SFML/SFML/wiki/Tutorial:-Manage-different-Screens (https://github.com/SFML/SFML/wiki/Tutorial:-Manage-different-Screens). My problem is that within my cscreen.hpp and screen_0.hpp I am getting a class undefined and redefinition error. Has anyone encountered this before or could it be an IDE(VS2013) setting I've messed up.

Minimal Code

cScreen.hpp
#include "SFML\Graphics.hpp"

class cScreen
{
public:
        virtual int Run(sf::RenderWindow &App) = 0;
};

screens.hpp
#ifndef SCREENS_HPP_INCLUDED
#define SCREENS_HPP_INCLUDED

//Basic Screen Class
#include "cScreen.hpp"

//Including each screen of application
#include "screen_0.hpp"

#endif // SCREENS_HPP_INCLUDED

Screen_0.hpp
#include <iostream>
#include "cScreen.hpp"

#include <SFML/Graphics.hpp>

class screen_0 : public cScreen
{
private:
        ...
public:
        screen_0(void);
        virtual int Run(sf::RenderWindow &App);
};

screen_0::screen_0(void)
{
    ...
}

int screen_0::Run(sf::RenderWindow &App)
{
        ...
}
 

main.cpp
#include <iostream>
#include <SFML/Graphics.hpp>
#include "screens.hpp"

int main(int argc, char** argv)
{
        ...
        return EXIT_SUCCESS;
}
 

ERRORS
Error   1   error C2011: 'cScreen' : 'class' type redefinition
Title: Re: C++ class redefinition and undefined using screen management
Post by: Forceofaqua on July 22, 2015, 07:36:05 pm
The post posted before I finished.

ERRORS
Error   1   error C2011: 'cScreen' : 'class' type redefinition    File: cScreen.hpp    Line: 4
Error   2   error C2504: 'cScreen' : base class undefined       File:screen_0.hpp   Line: 7
Title: Re: C++ class redefinition and undefined using screen management
Post by: Rosme on July 22, 2015, 07:36:43 pm
You don't have any header guards in your .hpp, except for screens.hpp (which you shouldn't do). You include cScreen.hpp in screen_0.hpp(bad name), and since you also include screens.hpp in your main, cScreen gets included twice, without header guards => redefinition.
Title: Re: C++ class redefinition and undefined using screen management
Post by: Forceofaqua on July 22, 2015, 07:42:27 pm
Ahh gotcha that makes sense, Thank you! I'm only using the names that were given in the tutorial at the link. I'm planning on changing it.