Заголовочные файлы проекта C++: ошибка "redefinition of `class ClassName'"
Разбил файл на 3 файла, и не получается его скомпилировать. Полагаю, ошибка в неправильном подключении заголовочных файлов.
SomeClass.h
#include "Update.h"
#include <iostream.h>
class SomeClass:public Updatable
{
int a;
public:
void start ()
{
std::cout<<"Start SomeClass\n";
}
void update ()
{
std::cout<<"SomeClass update: "<<a++<<'\n';
}
SomeClass ()
{
a=0;
}
};
void AddSomeClass ()
{
Updatemodule.AddToList (new SomeClass ());
}
Update.h
#include <vector>
#include <windows.h>
class Updatable
{
friend class UpdateModule;
virtual void start ()=0;
virtual void update ();
};
class UpdateModule
{
std::vector <Updatable*> script;
public:
void AddToList (Updatable*upd)
{
script.push_back (upd);
upd->start ();
}
void Start ()
{
}
void Update ()
{
while (1)
{
for (int i=0;i<script.size ();i++)
script [i]->update ();
Sleep (50);
}
}
}Updatemodule;
main.cpp
#include "Update.h"
#include "SomeClass.h"
void AddEvents ()
{
AddSomeClass ();
}
int main()
{
AddEvents ();
Updatemodule.Update ();
return 0;
}
--------------------Configuration: mingw5 - CUI Debug, Builder Type: MinGW--------------------
Checking file dependency...
Compiling C:\Users\Dmitry\Desktop\1\main.cpp...
[Error] C:\Users\Dmitry\Desktop\1\Update.h:5: error: redefinition of `class Updatable'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:5: error: previous definition of `class Updatable'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:12: error: redefinition of `class UpdateModule'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:12: error: previous definition of `class UpdateModule'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:34: error: invalid type in declaration before ';' token
[Error] C:\Users\Dmitry\Desktop\1\Update.h:34: error: conflicting declaration 'int Updatemodule'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:34: error: 'Updatemodule' has a previous declaration as `UpdateModule Updatemodule'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:34: error: type mismatch with previous external decl of `int Updatemodule'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:34: error: previous external decl of `UpdateModule Updatemodule'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:34: error: declaration of `int Updatemodule'
[Error] C:\Users\Dmitry\Desktop\1\Update.h:34: error: conflicts with previous declaration `UpdateModule Updatemodule'
[Warning] C:\PROGRA~2\C-FREE~1\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\backward\backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
Complete Make main: 11 error(s), 1 warning(s)
Источник: Stack Overflow на русском