Original Post
Keep getting annoying linking errors, and i cant work out what the last thing i did was !
--------------------Configuration: task3 - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
main.obj : error LNK2005: "public: void __thiscall Weapon::fireme(void)" (?fireme@Weapon@@QAEXXZ) already defined in char.obj
main.obj : error LNK2005: "public: void __thiscall Weapon::useme(void)" (?useme@Weapon@@QAEXXZ) already defined in char.obj
main.obj : error LNK2005: "public: __thiscall NPC::NPC(void)" (??0NPC@@QAE@XZ) already defined in char.obj
Debug/task3.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
task3.exe - 4 error(s), 0 warning(s)
Anyone have any suggestions ?
This the full code for the file i think my problem lies in.
#ifndef CHAR_H
#define CHAR_H
#include <iostream>
using namespace std;
// =============================================================
// BASIC Weapon class
// =============================================================
class Weapon
{
public:
// No constructor
// Accessor methods
void fireme(); // Fires the gun
void useme(); // I have decided that using a gun, really means hitting someone
// over the head with it. Otherwise whats the difference between
// fire and use ??
int GetWeaponAccuracy() { return m_iWeaponAccuracy; } // Gets private details
protected:
// private details
string m_sName; // Name of weapon
int m_iAmmo; // Amount of ammo
float m_iWeaponAccuracy; // How accurate is the weapon?
};
// =============================================================
// Weapons Accessor methods
// =============================================================
// FIRE
void Weapon::fireme()
{
if (m_iAmmo == 0)
{
cout << "Out of ammo" << endl;
return;
}
cout << "Bang, the weapon has fired" << endl;
m_iAmmo--;
return;
}
// USE
void Weapon::useme()
{
cout << "Smack, you just hit someone round the head with your weapon" << endl;
return;
}
// =============================================================
// AK47 of type Weapon
// =============================================================
class AK47 : public Weapon
{
public:
AK47(){ m_iAmmo=7;m_iWeaponAccuracy=0.3f;m_sName = "Desert Eagle";return;}
};
// =============================================================
// Pistol of type Weapon
// =============================================================
class Pistol : public Weapon
{
public:
Pistol(){ m_iAmmo=30;m_iWeaponAccuracy=0.8f;m_sName = "AK47";return;}
};
// =============================================================
// Character class
// =============================================================
class CCharacter {
public:
// No Constuctors
// Accessor methods
void fireweapon();
void useweapon();
protected:
Weapon* Weapon; // Weapon currently held
string m_sName; // Characters name
char m_cGender; // M = Male, F = Female, N = Neutral.
float m_fAccurate; // How accurate the character is with current gun.
// Changes depending on the gun.
};
// =============================================================
// None player character class
// =============================================================
class NPC : public CCharacter
{
public:
// Constuctor
NPC();
// Accessor methods
private:
float m_fAttackSkill; // How skilled the NPC is when attacking.
float m_fAimSkill; // Skill when aiming, a value between 0 and 1.
};
// =============================================================
// NPC methods
// =============================================================
NPC::NPC()
{
// Giving him a gun
Weapon = new AK47;
// Setting default values for the character
m_sName = "Default NPC Character";
m_cGender = ''M'';
// m_fAccurate Muh
m_fAttackSkill = 0.5;
m_fAimSkill = 0.5;
}
#endif