C++ Linker error
I get this error when i compile my project and it's related to these three pieces of code
I'm very confused
Prompt.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include "CalcularTamanho.h"
//#include "OrgTADS.h"
#include "tabDisp.cpp"
#include <iostream>
#include <string>
using namespace std;
class Prompt {
private :
CalcularTamanho calc;
// OrgTADS org;
public:
Prompt();
bool validarchar(char a[]);
void escolherOperacao(char *arg1, char *arg2);
};
Prompt::Prompt() {
bool second = false;
int i2 = 0;
char *bondi;
do {
char command[100]; // O Commando inteiro
cout << "Introduza o commando que deseja Executar (Commando de Saida: exit)";
cin.getline(command,100);
int length = calc.calcularTamanho(command);
cout << command;
bool test = validarchar(command);
if(test == 0) {
char arg1[2]; // O primeiro argumento
char arg2[40]; // O segundo argumento
for(int i = 0; i < length;i++)
{
if(second == false )
{
if(command[i] != ' ') {
arg1[i] = command[i];
} else {
arg1[i] = NULL;
second = true;
}
} else {
arg2[i2] = command[i];
i2++;
}
}
arg2[i2] = NULL;
char *ap1;
char *ap2;
ap1 = arg1;
ap2 = arg2;
escolherOperacao(arg1,arg2);
}
bondi = command;
system("pause");
}while(strcmp(bondi,"exit") != 0);
cout << "chego aqui";
system("pause");
}
bool Prompt::validarchar(char a[]) {
bool test = false;
int length = calc.calcularTamanho(a);
int i = 0;
while(!a[i] != NULL ) {
if(a[i] == ' ')
test = true;
i++;
}
return test;
}
void Prompt::escolherOperacao(char *arg1,char *arg2) {
if(strcmp(arg1,"IE") == 0) {
if(calc.calcularTamanho(arg2) != 3)
cout << "Erro na insercao .. tamanho inadequado de identificador de equipe: "+calc.calcularTamanho(arg2);
else
cout << "Muhahaha";
} else if(strcmp(arg1,"RJ") == 0) {
cout << "Opcao 2";
} else if(strcmp(arg1,"F5") == 0) {
cout << "Opcao 3";
}
}
int main() {
Prompt a;
}
|
tabDisp.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <iostream>
using namespace std;
#include "Lista.h"
class tabDisp
{
private:
Lista tabDispe[4];
public:
tabDisp();
~tabDisp();
void inserirElemento(char nome[],char id[]);
//T removerElemento(T &valor);
//bool pesquisarElemento(T &valor);
int funcaoDisp(char id[]);
//void listarTabelaDisp();
};
//construtor
tabDisp::tabDisp()
{
};
//desstrutor
tabDisp::~tabDisp()
{
};
//função de dispersão
int tabDisp::funcaoDisp(char id[])
{
int asc[3];
int i = 0;
int valor = 0;
for(i ; i < 3; i++) {
asc[i] = id[i];
valor = valor + asc[i];
}
cout << (valor % 4);
return (valor % 4);
};
//inserir elemento
void tabDisp::inserirElemento(char nome[],char id[])
{
int pos = funcaoDisp(id);
tabDispe[pos].insereEquipa(nome,id);
};
Lista::Lista()
{
headEq = NULL;
headJog = NULL;
tailEq = NULL;
tailJog = NULL;
};
//destrutor
Lista::~Lista()
{
};
//insere um determinado nó a cauda de uma lista
void Lista::insereEquipa(char nome2[25],char id2[3])
{
if(headEq == NULL) {
Equipa *nova = new Equipa;
nova -> next = NULL;
nova -> prev = NULL;
nova -> head = NULL;
nova -> nome[25] = nome2[25];
nova -> id[3] = id2[3];
headEq = nova;
tailEq = nova;
}
else {
Equipa *nova = new Equipa;
nova -> nome[25] = nome2[25];
nova -> id[3] = id2[3];
nova -> next = NULL;
nova -> prev = tailEq;
nova -> head = NULL;
tailEq = nova;
}
};
|
"Lista.h"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#ifndef _H_ListaM
#define _H_ListaM
class Lista
{
private:
struct Jogador
{
Jogador *next;
Jogador *prev;
int num;
char id[4];
char nome[15];
char apelido[15];
char pos[2];
};
struct Equipa
{
Equipa *next;
Equipa *prev;
Jogador *head;
char nome[25];
char id[3];
};
Equipa *headEq;
Jogador *headJog;
Equipa *tailEq;
Jogador *tailJog;
public:
Lista();
~Lista();
void insereEquipa(char nome[25],char id[3]);
};
#endif
|
This is The Error my compiler Visual Studio 2010 gives me
1>ClCompile:
1> Prompt.cpp
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>Prompt.obj : error LNK2005: "public: __thiscall Lista::Lista(void)" (??0Lista@@QAE@XZ) already defined in tabDisp.obj
1>Prompt.obj : error LNK2005: "public: __thiscall Lista::~Lista(void)" (??1Lista@@QAE@XZ) already defined in tabDisp.obj
1>Prompt.obj : error LNK2005: "public: void __thiscall Lista::insereEquipa(char * const,char * const)" (?insereEquipa@Lista@@QAEXQAD0@Z) already defined in tabDisp.obj
1>Prompt.obj : error LNK2005: "public: __thiscall tabDisp::tabDisp(void)" (??0tabDisp@@QAE@XZ) already defined in tabDisp.obj
1>Prompt.obj : error LNK2005: "public: __thiscall tabDisp::~tabDisp(void)" (??1tabDisp@@QAE@XZ) already defined in tabDisp.obj
1>Prompt.obj : error LNK2005: "public: int __thiscall tabDisp::funcaoDisp(char * const)" (?funcaoDisp@tabDisp@@QAEHQAD@Z) already defined in tabDisp.obj
1>Prompt.obj : error LNK2005: "public: void __thiscall tabDisp::inserirElemento(char * const,char * const)" (?inserirElemento@tabDisp@@QAEXQAD0@Z) already defined in tabDisp.obj
1>C:\Users\Rui Jorge\Documents\Visual Studio 2010\Projects\Tabalho Pratico Eda\Debug\Tabalho Pratico Eda.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
|
You shouldn't (usually) include a cpp file in another cpp file
Move the declaration of class tabDisp into its own header (tabDisp.h ??) and then include that rather than tabDisp.cpp (in Prompt.cpp)
You're already doing the right thing with Lista.h !!
Topic archived. No new replies allowed.