Dividindo Source em Arquivos
Pessoal, estou tentando apenas criar arquivos CPPs diferentes mas que sejam executados em um único MAIN juntos. Segue abaixo o código, e por fim o erro compilando pelo G++.
Main.cpp
#include <iostream>
#include <string>
#include "Classes.h"
#include "Character.cpp"
#include "Monster.cpp"
using namespace std;
int main() {
Monster Poring(80, 10, 347, 782);
EvilMonster Thanatos(15000, 70000, 423, 241, 9);
Character User("tiobilly", "", "", 99, NOVICE);
return 0;
}
Classes.h
/*
* File Description:
Este arquivo armazenada todas as classes disponíveis
no jogo, para adicionar uma classe é só adicionar uma linha
utilizando a vírgula na linha anterior.
* Created by: Bruno Alano (http://brunoalano.com.br)
*/
using namespace std;
/**
Characters Classes (Jobs) */
enum Jobs {
NOVICE, // 0
SWORDMAN, // 1
MAGE, // 2
PRIEST, // 3
SOUL_LINKER // 4
};
Character.cpp
#include <iostream>
#include <string>
#include "Classes.h"
using namespace std;
/**
Characters
Create a Character Object
*/
class Character {
protected:
string nickname;
string guildName;
string partyName;
Jobs job;
int accLvl;
public:
Character(const string n, const string gName, const string pName, int aLvl, Jobs j) {
nickname.append(n);
guildName.append(gName);
partyName.append(pName);
accLvl = aLvl;
job = j;
}
};
Monster.cpp
#include <iostream>
#include <string>
using namespace std;
/**
All Monsters Style
Simple monster, with no natural element.
Use:
Monster <monsterName> (<monster health>, <monster attack>,
<monster pos. x>, <monster pos. y>);
*/
class Monster {
int health, attackPower;
int x, y; / Position /
public:
int getHealth();
int getAttackPwr();
int getPositionX();
int getPositionY();
Monster(int h, int atk, int pX, int pY) {
this->health = h;
this->attackPower = atk;
this->x = pX;
this->y = pY;
}
};
/**
Return the Monster Health (HP) */
int Monster::getHealth() {
return this->health;
}
/**
Return the Monster Attack Power */
int Monster::getAttackPwr() {
return this->attackPower;
}
/**
Return the Monster Position X */
int Monster::getPositionX() {
return this->x;
}
/**
Return the Monster Position Y */
int Monster::getPositionY() {
return this->y;
}
/**
Evil Monster Element.
This type of monsters, has special skills and a element type.
Based on Monster class.
Use:
EvilMonster <monsterName> (<monster health>, <monster attack>,
<monster pos. x>, <monster pos. y>, <monster skill>);
*/
class EvilMonster : public Monster {
int skill;
public:
EvilMonster(int h, int atk, int pX, int pY, int skillNm) : Monster(h, atk, pX, pY) {
/ Evil Monster Define /
this->skill = skillNm;
}
int getSkill();
};
/**
Return the Evil Monster Special Skill */
int EvilMonster::getSkill() {
return this->skill;
}
ERRO:
>
C:\Temp\BrunoAlano>g++ Main.cpp Character.cpp Monster.cpp -o programa
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccATaaaa.o(.text+0x100):Monster.cpp: multi
ple definition of `Monster::getHealth()'
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccSwaaaa.o(.text+0x100):Main.cpp: first de
fined here
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccATaaaa.o(.text+0x10a):Monster.cpp: multi
ple definition of `Monster::getAttackPwr()'
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccSwaaaa.o(.text+0x10a):Main.cpp: first de
fined here
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccATaaaa.o(.text+0x116):Monster.cpp: multi
ple definition of `Monster::getPositionX()'
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccSwaaaa.o(.text+0x116):Main.cpp: first de
fined here
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccATaaaa.o(.text+0x122):Monster.cpp: multi
ple definition of `Monster::getPositionY()'
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccSwaaaa.o(.text+0x122):Main.cpp: first de
fined here
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccATaaaa.o(.text+0x12e):Monster.cpp: multi
ple definition of `EvilMonster::getSkill()'
C:\DOCUME~1\BRUNO~1.MED\CONFIG~1\Temp/ccSwaaaa.o(.text+0x12e):Main.cpp: first de
fined here
collect2: ld returned 1 exit status
C:\Temp\BrunoAlano>
Grato, Bruno Alano.
Discussão (1)
Carregando comentários...