0

I'm trying to create an Interface class:

// IScene.h
class IScene 
{
  public: virtual void Start() = 0;
  virtual void Loop() = 0;
  virtual void Exit() = 0;
};

// Template.cpp
#include "template.h"
#include "MainMenu.h"
#include "IScene.h"

using namespace AGK;
app App;

IScene * currentState;

void app::Begin(void) 
{
  currentState = new MainMenu();
}

IScene.h is not being called anywhere in the project, but compiler is still giving an error : Error : 'class' type redefinition for file IScene.h

vsoftco
  • 55,410
  • 12
  • 139
  • 252
Daqs
  • 720
  • 3
  • 8
  • 28
  • 1
    Does your header have include guards? – Barry May 26 '15 at 01:14
  • No. What are those? and why do I need them? Thanks for the quick reply. – Daqs May 26 '15 at 01:15
  • 1
    Add "#pragma once" to the top of your header file – RedAgito May 26 '15 at 01:17
  • See http://en.wikipedia.org/wiki/Include_guard – Oliver Dain May 26 '15 at 01:18
  • Does `template.h` or `MainMenu.h` include `IScene.h`? – Barmar May 26 '15 at 01:20
  • Struggling to find a good duplicate here. Maybe http://stackoverflow.com/q/2979384/2069064 ? – Barry May 26 '15 at 01:21
  • @Barmar MainMenu.h does include "IScene.h". I needed that in-order to extend the class MainMenu to IScene, as in MainMenu : public IScene so that I could add the abstract functions in MainMenu.h – Daqs May 26 '15 at 01:22
  • Then either use a header guard, or don't include `IScene.h` in `Template.cpp`. – Barmar May 26 '15 at 01:34
  • Header Guard worked! thanks guys. – Daqs May 26 '15 at 01:39
  • @RedAgito `#pragma once` has a couple of really nasty failure cases. Use it with caution. – user4581301 May 26 '15 at 01:41
  • @user4581301 I only know about it not being supported in older versions of gcc and that problems might arise when used with symbolic/hard links. Any other issues I should be aware of? I am using pragma once exclusively as inclusion guards for some time now and never had any problems – RedAgito May 26 '15 at 07:17
  • @RedAgito Other than it also being confused by network drives, that about covers it. I might just be working in a perfect storm where it crops up every time we have a new hire. – user4581301 May 26 '15 at 17:27

0 Answers0