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

Author Topic: C++ class redefinition and undefined using screen management  (Read 3212 times)

0 Members and 3 Guests are viewing this topic.

Forceofaqua

  • Newbie
  • *
  • Posts: 14
    • View Profile
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. 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

Forceofaqua

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: C++ class redefinition and undefined using screen management
« Reply #1 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

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: C++ class redefinition and undefined using screen management
« Reply #2 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.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

Forceofaqua

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: C++ class redefinition and undefined using screen management
« Reply #3 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.

 

anything