I have this class with variable configuration options. I want to include it in other classes: JugadorHumano
, JugadorIA
, Main
, PartidaClasica
, PartidaMision
.
#pragma once class Configuracion { public: static int MAX_ATAQUES; static int DIV_TERRITORIOS; }; int Configuracion::MAX_ATAQUES = 5; int Configuracion::DIV_TERRITORIOS = 3;
I want to be able to modify or read values ββfrom other classes. I cannot declare a static variable and define it in the declaration. I cannot allow these variables without a definition either because I get "Unresolved External" errors.
1>JugadorIA.obj : error LNK2005: "public: static int Configuracion::MAX_ATAQUES" \ ( ?MAX_ATAQUES@Configuracion @@2HA) already defined in JugadorHumano.obj 1>JugadorIA.obj : error LNK2005: "public: static int Configuracion::DIV_TERRITORIOS" \ ( ?DIV_TERRITORIOS@Configuracion @@2HA) already defined in JugadorHumano.obj 1>Main.obj : error LNK2005: "public: static int Configuracion::MAX_ATAQUES" \ ( ?MAX_ATAQUES@Configuracion @@2HA) already defined in JugadorHumano.obj 1>Main.obj : error LNK2005: "public: static int Configuracion::DIV_TERRITORIOS" \ ( ?DIV_TERRITORIOS@Configuracion @@2HA) already defined in JugadorHumano.obj 1>PartidaClasica.obj : error LNK2005: "public: static int Configuracion::MAX_ATAQUES" \ ( ?MAX_ATAQUES@Configuracion @@2HA) already defined in JugadorHumano.obj 1>PartidaClasica.obj : error LNK2005: "public: static int Configuracion::DIV_TERRITORIOS" \ ( ?DIV_TERRITORIOS@Configuracion @@2HA) already defined in JugadorHumano.obj 1>PartidaMision.obj : error LNK2005: "public: static int Configuracion::MAX_ATAQUES" \ ( ?MAX_ATAQUES@Configuracion @@2HA) already defined in JugadorHumano.obj 1>PartidaMision.obj : error LNK2005: "public: static int Configuracion::DIV_TERRITORIOS" \ ( ?DIV_TERRITORIOS@Configuracion @@2HA) already defined in JugadorHumano.obj 1>D:\Leire\My Dropbox\Carpetas compartidas\Compartidos Victor\Practicas POO II\P3\P3M10\Debug\P3M10.exe : fatal error LNK1169: one or more multiply defined symbols found
What should I do to avoid this override that I get? I cannot understand this, and I cannot find a similar problem.
Zhertal
source share