Hello,
When i compile i get theses undefiend reference to extern lobal variable. In my code, i try to do an file
that define it and extern it on SystemeBataille.cpp call th definitor on main.cpp but same error. If i place my extern on an specific function exemple SystemeBataille::placeExternHere i get an not declared error. First question: Do my file for defined variables is useful and do something wrong? Second Question: Do as a beginner i'm better to place all in same file with one and only header with variables as protected? and Thirth Question: There an way for define and extern it correctly? If that only links how i get it linked with Code::Blocks with MnGW? and last one: If i use extern on header file as i see on web i get an storage class problem
Sorry if variable and functions name are in french i'm not primary english user
Here my codes:
SystemeBataille.cpp
#include "Personnage.h"
#include "Ennemis.h"
#include "LevelUp.h"
#include "SystemeBataille.h"
#include "Barbare.h"
#include "Magicien.h"
#include "InitVariable.h"
#include <iostream>
#include <string>
using namespace std;
extern int m_StatsVieActuelPerso;
extern int m_StatsVieMaxPerso;
extern int m_StatsVitPerso;
extern int m_StatsMpActuelPerso;
extern int m_StatsMpMaxPerso;
extern int m_StatsStrPerso;
extern int m_StatsRstPerso;
extern int m_StatsBaseDmgPerso;
extern int vieRegenerer;
extern int magieRegenerer;
extern int pointsExperience;
extern std::string barbare;
extern std::string sorcier;
extern std::string pasteur;
extern std::string classeDuJoueur;
extern std::string nomEnnemi;
extern int statsVieMaxEnnemi;
extern int statsVieActuelEnnemi;
extern int statsMpActuelEnnemi;
extern int statsStrEnnemi;
extern int statsRstEnnemi;
extern int statsVitEnnemi;
extern int statsBaseDmgEnnemi;
SystemeBataille::SystemeBataille()
{
}
void SystemeBataille::roundePreparation()
{
std::string transfererNomEnnemi = nomEnnemi;
transfererVieMaxEnnemi = statsVieMaxEnnemi;
transfererVieActuelEnnemi = statsVieActuelEnnemi;
transfererMpEnnemi = statsMpActuelEnnemi;
transfererForceEnnemi = statsStrEnnemi;
transfererResistanceEnnemi = statsRstEnnemi;
transfererVitesseEnnemi = statsVitEnnemi;
transfererDegatsEnnemi = transfererDegatsEnnemi;
transfererDegatBaseEnnemi = statsBaseDmgEnnemi;
}
void SystemeBataille::determinerTour()
{
if (statsVitEnnemi > m_StatsVitPerso)
{
tourDecider = 1;
}
else (statsVitEnnemi == m_StatsVitPerso);
{
tourDecider = 0;
}
if (m_StatsVitPerso > statsVitEnnemi)
{
tourDecider = 2;
}
}
void SystemeBataille::aNommer()
{
}
SystemeBataille.h
#ifndef SYSTEMEBATAILLE_H_INCLUDED
#define SYSTEMEBATAILLE_H_INCLUDED
#include <iostream>
#include <string>
#include "Personnage.h"
#include "Ennemis.h"
class SystemeBataille
{
public:
SystemeBataille();
void roundePreparation();
void aNommer();
void determinerTour();
protected:
std::string transfererNomEnnemi;
int transfererVieMaxEnnemi;
int transfererVieActuelEnnemi;
int transfererMpEnnemi;
int transfererForceEnnemi;
int transfererResistanceEnnemi;
int transfererVitesseEnnemi;
int transfererDegatsEnnemi;
int transfererDegatBaseEnnemi;
int tourDecider;
};
#endif // SYSTEMEBATAILLE_H_INCLUDED
InitVariable.cpp
#include "Personnage.h"
#include "InitVariable.h"
#include "Ennemis.h"
#include "LevelUp.h"
#include "SystemeBataille.h"
#include "Barbare.h"
#include "Magicien.h"
#include "UtiliserObjet.h"
InitVariable::InitVariable()
{
}
void InitVariable::InitialiserVariable()
{
int m_StatsVieActuelPerso = 0;
int m_StatsVieMaxPerso = 0;
int m_StatsVitPerso = 0;
int m_StatsMpActuelPerso = 0;
int m_StatsMpMaxPerso = 0;
int m_StatsStrPerso = 0;
int m_StatsRstPerso = 0;
int m_StatsBaseDmgPerso = 0;
int vieRegenerer = 0;
int magieRegenerer = 0;
int pointsExperience = 0;
std::string barbare;
std::string sorcier;
std::string pasteur;
std::string classeDuJoueur;
std::string nomEnnemi;
int statsVieMaxEnnemi = 0;
int statsVieActuelEnnemi = 0;
int statsMpActuelEnnemi = 0;
int statsStrEnnemi = 0;
int statsRstEnnemi = 0;
int statsVitEnnemi = 0;
int statsBaseDmgEnnemi = 0;
}
InitVariable.h
#ifndef INITVARIABLE_H_INCLUDED
#define INITVARIABLE_H_INCLUDED
#include "Personnage.h"
#include "Ennemis.h"
#include "SystemeBataille.h"
#include "InitVariable.h"
class InitVariable
{
public:
InitVariable();
void InitialiserVariable();
};
#endif // INITVARIABLE_H_INCLUDED
and finally main.cpp
#include <iostream>
#include <string>
#include "Personnage.h"
#include "Ennemis.h"
#include "Barbare.h"
#include "Magicien.h"
#include "LevelUp.h"
#include "UtiliserObjet.h"
#include "SystemeBataille.h"
#include "InitVariable.h"
using namespace std;
int main()
{
InitVariable initvar;
initvar.InitialiserVariable();
return 0;
}
Thanks i nadvance