Multiple definition

Status
Niet open voor verdere reacties.

Arjan B

Gebruiker
Lid geworden
11 dec 2006
Berichten
364
Ik krijg in mijn project een fout "multiple definition of 'AGE_ErrorString' ".
Nu zou ik dan denken dat ik ergens AGE_ErrorString twee keer definieer of dat ik twee headers elkaar laat includen ofzo..
Maar ik zie nergens waar ik dat doe :P

Ziet iemand misschien waarom hij zo'n fout zou geven?

AGE.h
PHP:
 /* Include this only once */
#ifndef AGE_H
#define AGE_H

 /* Don't include MFC */
#define WIN32_LEAN_AND_MEAN
 /* Windows header */
#include <windows.h>
 /* AGE typedef header */
#include "AGE_Types.h"
 /* AGE error header */
#include "AGE_Error.h"

..........

#endif

AGE_Types.h
PHP:
/* Include this only once */
#ifndef AGE_TYPES_H
#define AGE_TYPES_H

 /* Typedefs */
typedef signed   char  AGEint8;
typedef unsigned char  AGEuint8;
typedef signed   short AGEint16;
typedef unsigned short AGEuint16;
typedef signed   long  AGEint32;
typedef unsigned long  AGEuint32;
typedef signed   int   AGEint;
typedef unsigned int   AGEuint;
typedef          float AGEfloat;
typedef          bool  AGEbool;
typedef          char* AGEstring;

#endif

main.cpp
PHP:
 /* Don't include MFC */
#define WIN32_LEAN_AND_MEAN
 /* Windows header */
#include <windows.h>
 /* AGE header */
#include "AGE.h"

.................

AGE_Error.h
PHP:
 /* Include this only once */
#ifndef AGE_ERROR_H
#define AGE_ERROR_H

 /* AGE typedef header */
#include "AGE.h"

 /* Return error enumeration */
enum AGE_Error
{
  AGE_NoError = 0,
  AGE_ErrorRegisterClass,
  AGE_ErrorCreateWindow
};

 /* String array holding explanation about the error */
AGEstring AGE_ErrorString[3] =
{
  "No error has occurred.\n",
  "Could not register the window class.\n",
  "Could not create the window.\n"
};

#endif

AGE.cpp
PHP:
 /* Complement header file */
#include "AGE.h"

...................

Alvast bedankt ^^.


----------------------------------


Edit: Snap nu eindelijk de debugger van Dev-C++ een beetje.. :P Hij geeft aan dat die fout ergens in de constructor van AGE_Window zit..

PHP:
 /* Include this only once */
#ifndef AGE_H
#define AGE_H

 /* Don't include MFC */
#define WIN32_LEAN_AND_MEAN
 /* Windows header */
#include <windows.h>
 /* AGE typedef header */
#include "AGE_Types.h"
 /* AGE error header */
#include "AGE_Error.h"

 /* Window procedure declaration */
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);

 /* AGE_Window class */
class AGE_Window
{
  public:
    AGE_Window();
    ~AGE_Window();
    AGE_Error Init(HINSTANCE hInstance, AGEstring szCaption, AGEuint16 iWidth, AGEuint16 iHeight,
                   AGEuint16 iBPP, const AGEstring szClassName = "AGE_App" );
  private:
    HWND      m_hWnd;
    AGEstring m_Caption;
    AGEuint16 m_iScreenWidth;
    AGEuint16 m_iScreenHeight;
    AGEuint16 m_iScreenBPP;
};

#endif

AGE.cpp
PHP:
/* Complement header file */
#include "AGE.h"

 /* Constructor */
AGE_Window::AGE_Window()
{    //  <-------------------------- Daar geeft ie fout
   /* Init members */
  m_hWnd          = NULL;
  m_Caption       = "An AGE application";
  m_iScreenWidth  = 640;
  m_iScreenHeight = 480;
  m_iScreenBPP    = 16;
}
 
Laatst bewerkt:
Een reactie op een ander forum heeft voor een oplossing gezorgd ^^:

Gepost door D Drmmr:
In het bestand AGE_Error.h definieer je de variabele AGE_ErrorString. Je moet hem in het .h bestand alleen declareren en in het .cpp bestand pas definiëren.
Code:
// .h file
extern AGEstring AGE_ErrorString[3];
// .cpp file
AGEstring AGE_ErrorString[3] =
{
  "No error has occurred.\n",
  "Could not register the window class.\n",
  "Could not create the window.\n"
};
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan