Thread: What would be the best way to incorporate another class's function to your own class?

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    71

    What would be the best way to incorporate another class's function to your own class?

    For background, I am creating a mod for Half Life 2 and want to add one weapon's functionality to all the other weapons. I am editting a class CWeaponCrossbow where I want to add the functionality of the CWeaponPhysCannon class. I tried just including the weapon_physcannon.cpp into the weapon_crossbow.cpp but run into the below errors. Both weapon cpp files have their include files which mostly don't overlap. What would be the best path to a physcannon's method into the crossbow? I also tried making the physcannon a friend class of the crossbow but that gives "incomplete type is not allowed error" when trying to call the physcannon's method. I have a good understanding of the call hierarchy when trying to execute a piece of code I just don't have the C++ background to implement them elegantly.

    Thanks for the help.

    Code:
    2>weapon_physcannon.obj : error LNK2005: "public: static struct datamap_t * __cdecl game_shadowcontrol_params_t::GetBaseMap(void)" (?GetBaseMap@game_shadowcontrol_params_t@@SAPAUdatamap_t@@XZ) already defined in weapon_crossbow.obj2>weapon_physcannon.obj : error LNK2005: "private: static struct datamap_t * __cdecl CGrabController::GetBaseMap(void)" (?GetBaseMap@CGrabController@@CAPAUdatamap_t@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CGrabController::OnRestore(void)" (?OnRestore@CGrabController@@QAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual enum IMotionEvent::simresult_e __thiscall CGrabController::Simulate(class IPhysicsMotionController *,class IPhysicsObject *,float,class Vector &,class Vector &)" (?Simulate@CGrabController@@UAE?AW4simresult_e@IMotionEvent@@PAVIPhysicsMotionController@@PAVIPhysicsObject@@MAAVVector@@2@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "private: virtual struct datamap_t * __thiscall CPlayerPickupController::GetDataDescMap(void)" (?GetDataDescMap@CPlayerPickupController@@EAEPAUdatamap_t@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: static struct datamap_t * __cdecl thrown_objects_t::GetBaseMap(void)" (?GetBaseMap@thrown_objects_t@@SAPAUdatamap_t@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual class ServerClass * __thiscall CWeaponPhysCannon::GetServerClass(void)" (?GetServerClass@CWeaponPhysCannon@@UAEPAVServerClass@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual int __thiscall CWeaponPhysCannon::YouForgotToImplementOrDeclareServerClass(void)" (?YouForgotToImplementOrDeclareServerClass@CWeaponPhysCannon@@UAEHXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual struct datamap_t * __thiscall CWeaponPhysCannon::GetDataDescMap(void)" (?GetDataDescMap@CWeaponPhysCannon@@UAEPAUdatamap_t@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "bool __cdecl PlayerHasMegaPhysCannon(void)" (?PlayerHasMegaPhysCannon@@YA_NXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::Precache(void)" (?Precache@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::WeaponIdle(void)" (?WeaponIdle@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: float __thiscall CWeaponPhysCannon::GetLoadPercentage(void)" (?GetLoadPercentage@CWeaponPhysCannon@@IAEMXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual char const * __thiscall CWeaponPhysCannon::GetShootSound(int)const " (?GetShootSound@CWeaponPhysCannon@@UBEPBDH@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class IPhysicsObject * __cdecl GetRagdollChildAtPosition(class CBaseEntity *,class Vector const &)" (?GetRagdollChildAtPosition@@YAPAVIPhysicsObject@@PAVCBaseEntity@@ABVVector@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "private: void __thiscall CGrabController::ComputeMaxSpeed(class CBaseEntity *,class IPhysicsObject *)" (?ComputeMaxSpeed@CGrabController@@AAEXPAVCBaseEntity@@PAVIPhysicsObject@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: class QAngle __thiscall CGrabController::TransformAnglesToPlayerSpace(class QAngle const &,class CBasePlayer *)" (?TransformAnglesToPlayerSpace@CGrabController@@QAE?AVQAngle@@ABV2@PAVCBasePlayer@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: class QAngle __thiscall CGrabController::TransformAnglesFromPlayerSpace(class QAngle const &,class CBasePlayer *)" (?TransformAnglesFromPlayerSpace@CGrabController@@QAE?AVQAngle@@ABV2@PAVCBasePlayer@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CGrabController::DetachEntity(bool)" (?DetachEntity@CGrabController@@QAEX_N@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: float __thiscall CGrabController::GetSavedMass(class IPhysicsObject *)" (?GetSavedMass@CGrabController@@QAEMPAVIPhysicsObject@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: bool __thiscall CGrabController::IsObjectAllowedOverhead(class CBaseEntity *)" (?IsObjectAllowedOverhead@CGrabController@@QAE_NPAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "private: static struct datamap_t * __cdecl CPlayerPickupController::GetBaseMap(void)" (?GetBaseMap@CPlayerPickupController@@CAPAUdatamap_t@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: bool __thiscall CPlayerPickupController::IsHoldingEntity(class CBaseEntity *)" (?IsHoldingEntity@CPlayerPickupController@@QAE_NPAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: static struct datamap_t * __cdecl CWeaponPhysCannon::GetBaseMap(void)" (?GetBaseMap@CWeaponPhysCannon@@SAPAUdatamap_t@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::SetViewModel(void)" (?SetViewModel@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual bool __thiscall CWeaponPhysCannon::CanHolster(void)" (?CanHolster@CWeaponPhysCannon@@UAE_NXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DryFire(void)" (?DryFire@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::PrimaryFireEffect(void)" (?PrimaryFireEffect@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::ApplyVelocityBasedForce(class CBaseEntity *,class Vector const &,class Vector const &,enum PhysGunForce_t)" (?ApplyVelocityBasedForce@CWeaponPhysCannon@@IAEXPAVCBaseEntity@@ABVVector@@1W4PhysGunForce_t@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: float __thiscall CWeaponPhysCannon::TraceLength(void)" (?TraceLength@CWeaponPhysCannon@@IAEMXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: class CSoundPatch * __thiscall CWeaponPhysCannon::GetMotorSound(void)" (?GetMotorSound@CWeaponPhysCannon@@IAEPAVCSoundPatch@@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::StopLoopingSounds(void)" (?StopLoopingSounds@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "bool __cdecl PlayerPickupControllerIsHoldingEntity(class CBaseEntity *,class CBaseEntity *)" (?PlayerPickupControllerIsHoldingEntity@@YA_NPAVCBaseEntity@@0@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "float __cdecl PhysCannonGetHeldObjectMass(class CBaseCombatWeapon *,class IPhysicsObject *)" (?PhysCannonGetHeldObjectMass@@YAMPAVCBaseCombatWeapon@@PAVIPhysicsObject@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class CBaseEntity * __cdecl PhysCannonGetHeldEntity(class CBaseCombatWeapon *)" (?PhysCannonGetHeldEntity@@YAPAVCBaseEntity@@PAVCBaseCombatWeapon@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "float __cdecl PlayerPickupGetHeldObjectMass(class CBaseEntity *,class IPhysicsObject *)" (?PlayerPickupGetHeldObjectMass@@YAMPAVCBaseEntity@@PAVIPhysicsObject@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "void __cdecl UTIL_PhyscannonTraceHull(class Vector const &,class Vector const &,class Vector const &,class Vector const &,class CBaseEntity *,class CGameTrace *)" (?UTIL_PhyscannonTraceHull@@YAXABVVector@@000PAVCBaseEntity@@PAVCGameTrace@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: __thiscall CGrabController::CGrabController(void)" (??0CGrabController@@QAE@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: __thiscall CGrabController::~CGrabController(void)" (??1CGrabController@@QAE@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CGrabController::SetTargetPosition(class Vector const &,class QAngle const &)" (?SetTargetPosition@CGrabController@@QAEXABVVector@@ABVQAngle@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: float __thiscall CGrabController::ComputeError(void)" (?ComputeError@CGrabController@@QAEMXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CGrabController::AttachEntity(class CBasePlayer *,class CBaseEntity *,class IPhysicsObject *,bool,class Vector const &,bool)" (?AttachEntity@CGrabController@@QAEXPAVCBasePlayer@@PAVCBaseEntity@@PAVIPhysicsObject@@_NABVVector@@3@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "int __cdecl ServerClassInit<struct DT_WeaponPhysCannon::ignored>(struct DT_WeaponPhysCannon::ignored *)" (??$ServerClassInit@Uignored@DT_WeaponPhysCannon@@@@YAHPAUignored@DT_WeaponPhysCannon@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::PuntNonVPhysics(class CBaseEntity *,class Vector const &,class CGameTrace &)" (?PuntNonVPhysics@CWeaponPhysCannon@@IAEXPAVCBaseEntity@@ABVVector@@AAVCGameTrace@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: bool __thiscall CWeaponPhysCannon::EntityAllowsPunts(class CBaseEntity *)" (?EntityAllowsPunts@CWeaponPhysCannon@@IAE_NPAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: bool __thiscall CWeaponPhysCannon::CanPickupObject(class CBaseEntity *)" (?CanPickupObject@CWeaponPhysCannon@@IAE_NPAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DestroyEffects(void)" (?DestroyEffects@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoEffectNone(void)" (?DoEffectNone@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class CBaseEntity * __cdecl GetPlayerHeldEntity(class CBasePlayer *)" (?GetPlayerHeldEntity@@YAPAVCBaseEntity@@PAVCBasePlayer@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "void __cdecl UTIL_PhyscannonTraceLine(class Vector const &,class Vector const &,class CBaseEntity *,class CGameTrace *)" (?UTIL_PhyscannonTraceLine@@YAXABVVector@@0PAVCBaseEntity@@PAVCGameTrace@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::UpdateOnRemove(void)" (?UpdateOnRemove@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::FindObjectTrace(class CBasePlayer *,class CGameTrace *)" (?FindObjectTrace@CWeaponPhysCannon@@IAEXPAVCBasePlayer@@PAVCGameTrace@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: class CBaseEntity * __thiscall CWeaponPhysCannon::MegaPhysCannonFindObjectInCone(class Vector const &,class Vector const &,float,float,bool)" (?MegaPhysCannonFindObjectInCone@CWeaponPhysCannon@@IAEPAVCBaseEntity@@ABVVector@@0MM_N@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: class CBaseEntity * __thiscall CWeaponPhysCannon::FindObjectInCone(class Vector const &,class Vector const &,float)" (?FindObjectInCone@CWeaponPhysCannon@@IAEPAVCBaseEntity@@ABVVector@@0M@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: bool __thiscall CGrabController::UpdateObject(class CBasePlayer *,float)" (?UpdateObject@CGrabController@@QAE_NPAVCBasePlayer@@M@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CWeaponPhysCannon::PurgeThrownObjects(void)" (?PurgeThrownObjects@CWeaponPhysCannon@@QAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: bool __thiscall CWeaponPhysCannon::IsAccountableForObject(class CBaseEntity *)" (?IsAccountableForObject@CWeaponPhysCannon@@QAE_NPAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "bool __cdecl PhysCannonAccountableForObject(class CBaseCombatWeapon *,class CBaseEntity *)" (?PhysCannonAccountableForObject@@YA_NPAVCBaseCombatWeapon@@PAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CPlayerPickupController::Shutdown(bool)" (?Shutdown@CPlayerPickupController@@QAEX_N@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CPlayerPickupController::Use(class CBaseEntity *,class CBaseEntity *,enum USE_TYPE,float)" (?Use@CPlayerPickupController@@UAEXPAVCBaseEntity@@0W4USE_TYPE@@M@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: __thiscall CWeaponPhysCannon::CWeaponPhysCannon(void)" (??0CWeaponPhysCannon@@QAE@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::Spawn(void)" (?Spawn@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::WaitForUpgradeThink(void)" (?WaitForUpgradeThink@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * __cdecl DataMapInit<class CPlayerPickupController>(class CPlayerPickupController *)" (??$DataMapInit@VCPlayerPickupController@@@@YAPAUdatamap_t@@PAVCPlayerPickupController@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CPlayerPickupController::Init(class CBasePlayer *,class CBaseEntity *)" (?Init@CPlayerPickupController@@QAEXPAVCBasePlayer@@PAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "void __cdecl PlayerPickupObject(class CBasePlayer *,class CBaseEntity *)" (?PlayerPickupObject@@YAXPAVCBasePlayer@@PAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * __cdecl DataMapInit<struct thrown_objects_t>(struct thrown_objects_t *)" (??$DataMapInit@Uthrown_objects_t@@@@YAPAUdatamap_t@@PAUthrown_objects_t@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * __cdecl DataMapInit<class CWeaponPhysCannon>(class CWeaponPhysCannon *)" (??$DataMapInit@VCWeaponPhysCannon@@@@YAPAUdatamap_t@@PAVCWeaponPhysCannon@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CWeaponPhysCannon::BeginUpgrade(void)" (?BeginUpgrade@CWeaponPhysCannon@@QAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoEffectClosed(void)" (?DoEffectClosed@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoMegaEffectClosed(void)" (?DoMegaEffectClosed@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoEffectReady(void)" (?DoEffectReady@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoEffectHolding(void)" (?DoEffectHolding@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoMegaEffectHolding(void)" (?DoMegaEffectHolding@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoMegaEffectReady(void)" (?DoMegaEffectReady@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CWeaponPhysCannon::RecordThrownObject(class CBaseEntity *)" (?RecordThrownObject@CWeaponPhysCannon@@QAEXPAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "void __cdecl PhysCannonBeginUpgrade(class CBaseAnimating *)" (?PhysCannonBeginUpgrade@@YAXPAVCBaseAnimating@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * __cdecl DataMapInit<struct game_shadowcontrol_params_t>(struct game_shadowcontrol_params_t *)" (??$DataMapInit@Ugame_shadowcontrol_params_t@@@@YAPAUdatamap_t@@PAUgame_shadowcontrol_params_t@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * __cdecl DataMapInit<class CGrabController>(class CGrabController *)" (??$DataMapInit@VCGrabController@@@@YAPAUdatamap_t@@PAVCGrabController@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::Physgun_OnPhysGunPickup(class CBaseEntity *,class CBasePlayer *,enum PhysGunPickup_t)" (?Physgun_OnPhysGunPickup@CWeaponPhysCannon@@IAEXPAVCBaseEntity@@PAVCBasePlayer@@W4PhysGunPickup_t@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::PuntVPhysics(class CBaseEntity *,class Vector const &,class CGameTrace &)" (?PuntVPhysics@CWeaponPhysCannon@@IAEXPAVCBaseEntity@@ABVVector@@AAVCGameTrace@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::PuntRagdoll(class CBaseEntity *,class Vector const &,class CGameTrace &)" (?PuntRagdoll@CWeaponPhysCannon@@IAEXPAVCBaseEntity@@ABVVector@@AAVCGameTrace@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DetachObject(bool,bool)" (?DetachObject@CWeaponPhysCannon@@IAEX_N0@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoEffectLaunch(class Vector *)" (?DoEffectLaunch@CWeaponPhysCannon@@IAEXPAVVector@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoMegaEffectLaunch(class Vector *)" (?DoMegaEffectLaunch@CWeaponPhysCannon@@IAEXPAVVector@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoMegaEffect(int,class Vector *)" (?DoMegaEffect@CWeaponPhysCannon@@IAEXHPAVVector@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::UpdateObject(void)" (?UpdateObject@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::ItemPreFrame(void)" (?ItemPreFrame@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::StartEffects(void)" (?StartEffects@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoEffect(int,class Vector *)" (?DoEffect@CWeaponPhysCannon@@IAEXHPAVVector@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::OnRestore(void)" (?OnRestore@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::LaunchObject(class Vector const &,float)" (?LaunchObject@CWeaponPhysCannon@@IAEXABVVector@@M@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::OpenElements(void)" (?OpenElements@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::CloseElements(void)" (?CloseElements@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::StopEffects(bool)" (?StopEffects@CWeaponPhysCannon@@IAEX_N@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual bool __thiscall CWeaponPhysCannon::Deploy(void)" (?Deploy@CWeaponPhysCannon@@UAE_NXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: void __thiscall CWeaponPhysCannon::ForceDrop(void)" (?ForceDrop@CWeaponPhysCannon@@QAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: bool __thiscall CWeaponPhysCannon::DropIfEntityHeld(class CBaseEntity *)" (?DropIfEntityHeld@CWeaponPhysCannon@@QAE_NPAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::Drop(class Vector const &)" (?Drop@CWeaponPhysCannon@@UAEXABVVector@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual bool __thiscall CWeaponPhysCannon::Holster(class CBaseCombatWeapon *)" (?Holster@CWeaponPhysCannon@@UAE_NPAVCBaseCombatWeapon@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::PrimaryAttack(void)" (?PrimaryAttack@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::Force(void)" (?Force@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: bool __thiscall CWeaponPhysCannon::AttachObject(class CBaseEntity *,class Vector const &)" (?AttachObject@CWeaponPhysCannon@@IAE_NPAVCBaseEntity@@ABVVector@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: enum CWeaponPhysCannon::FindObjectResult_t __thiscall CWeaponPhysCannon::FindObject(void)" (?FindObject@CWeaponPhysCannon@@IAE?AW4FindObjectResult_t@1@XZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::CheckForTarget(void)" (?CheckForTarget@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: void __thiscall CWeaponPhysCannon::DoEffectIdle(void)" (?DoEffectIdle@CWeaponPhysCannon@@IAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::ItemBusyFrame(void)" (?ItemBusyFrame@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::ItemPostFrame(void)" (?ItemPostFrame@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "void __cdecl PhysCannonForceDrop(class CBaseCombatWeapon *,class CBaseEntity *)" (?PhysCannonForceDrop@@YAXPAVCBaseCombatWeapon@@PAVCBaseEntity@@@Z) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: virtual void __thiscall CWeaponPhysCannon::SecondaryAttack(void)" (?SecondaryAttack@CWeaponPhysCannon@@UAEXXZ) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: static struct datamap_t game_shadowcontrol_params_t::m_DataMap" (?m_DataMap@game_shadowcontrol_params_t@@2Udatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "private: static struct datamap_t CGrabController::m_DataMap" (?m_DataMap@CGrabController@@0Udatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "private: static struct datamap_t CPlayerPickupController::m_DataMap" (?m_DataMap@CPlayerPickupController@@0Udatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: static struct datamap_t thrown_objects_t::m_DataMap" (?m_DataMap@thrown_objects_t@@2Udatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: static bool CWeaponPhysCannon::m_sbStaticPoseParamsLoaded" (?m_sbStaticPoseParamsLoaded@CWeaponPhysCannon@@1_NA) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "protected: static int CWeaponPhysCannon::m_poseActive" (?m_poseActive@CWeaponPhysCannon@@1HA) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: static class SendTable * CWeaponPhysCannon::m_pClassSendTable" (?m_pClassSendTable@CWeaponPhysCannon@@2PAVSendTable@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "public: static struct datamap_t CWeaponPhysCannon::m_DataMap" (?m_DataMap@CWeaponPhysCannon@@2Udatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * CWeaponPhysCannon_DataDescInit::g_DataMapHolder" (?g_DataMapHolder@CWeaponPhysCannon_DataDescInit@@3PAUdatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "int DT_WeaponPhysCannon::g_SendTableInit" (?g_SendTableInit@DT_WeaponPhysCannon@@3HA) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class SendTable DT_WeaponPhysCannon::g_SendTable" (?g_SendTable@DT_WeaponPhysCannon@@3VSendTable@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * thrown_objects_t_DataDescInit::g_DataMapHolder" (?g_DataMapHolder@thrown_objects_t_DataDescInit@@3PAUdatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * CPlayerPickupController_DataDescInit::g_DataMapHolder" (?g_DataMapHolder@CPlayerPickupController_DataDescInit@@3PAUdatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * CGrabController_DataDescInit::g_DataMapHolder" (?g_DataMapHolder@CGrabController_DataDescInit@@3PAUdatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "struct datamap_t * game_shadowcontrol_params_t_DataDescInit::g_DataMapHolder" (?g_DataMapHolder@game_shadowcontrol_params_t_DataDescInit@@3PAUdatamap_t@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_right_turrets" (?physcannon_right_turrets@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_dmg_glass" (?physcannon_dmg_glass@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar player_throwforce" (?player_throwforce@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_punt_cone" (?physcannon_punt_cone@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_ball_cone" (?physcannon_ball_cone@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_cone" (?physcannon_cone@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_mega_pullforce" (?physcannon_mega_pullforce@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_pullforce" (?physcannon_pullforce@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_chargetime" (?physcannon_chargetime@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_mega_tracelength" (?physcannon_mega_tracelength@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_tracelength" (?physcannon_tracelength@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_maxmass" (?physcannon_maxmass@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_maxforce" (?physcannon_maxforce@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_minforce" (?physcannon_minforce@@3VConVar@@A) already defined in weapon_crossbow.obj
    2>weapon_physcannon.obj : error LNK2005: "class ConVar g_debug_physcannon" (?g_debug_physcannon@@3VConVar@@A) already defined in weapon_crossbow.obj

  2. #2
    Registered User
    Join Date
    Jun 2013
    Posts
    56
    If the function is already created and does exactly what you need. Why would you bother to include it? Just include the header. Make the physcannon object and call its function when you need it. Just don't call a display function.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    71
    Quote Originally Posted by Ewiv View Post
    If the function is already created and does exactly what you need. Why would you bother to include it? Just include the header. Make the physcannon object and call its function when you need it. Just don't call a display function.
    It's already been created yes but including the physcannon cpp file causes errors related to overlapping #includes with the crossbow cpp file which results in many errors such as this one.
    Code:
    1>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_minforce" (?physcannon_minforce@@3VConVar@@A) already defined in weapon_crossbow.obj

  4. #4
    Registered User
    Join Date
    Jun 2013
    Posts
    56
    Quote Originally Posted by workisnotfun View Post
    It's already been created yes but including the physcannon cpp file causes errors related to overlapping #includes with the crossbow cpp file which results in many errors such as this one.
    Code:
    1>weapon_physcannon.obj : error LNK2005: "class ConVar physcannon_minforce" (?physcannon_minforce@@3VConVar@@A) already defined in weapon_crossbow.obj
    You will note I said the header file.

    .cpp is usual the implementation, you do not generally include the implementation file you include the header file which is .h

    Your long list of errors is because you are including the implementation file which is in effect defining all the functions of physcannon a 2nd time, that is what it is unhappy about. You can't redefine a function with exactly the same parameters, you can overload a function with additional parameters however
    Last edited by Ewiv; 12-12-2013 at 08:45 PM.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    71
    That makes sense.

    The physcannon class a function that uses its members but is NOT part of the crossbow class and I'm trying to incorporate in. Would you have a suggestion for how to do that?

    The method uses a lot of the physcannon's other methods and is quite complicated enough that I don't think I can just extract the relevant code out and implant it to the crossbow though. Thanks!

  6. #6
    Registered User
    Join Date
    Jun 2013
    Posts
    56
    If you include the header for physcannon you could just in your implementation create an object of it, much like declaring a variable

    Code:
    physcannon myCannon;
    And then do something like this for when you want to fire it
    Code:
    myCannon.fire();
    This is all hypothetical as I have not looked at the code for any of this so I just used a random function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Member function from class as a friend in another class
    By thames in forum C++ Programming
    Replies: 18
    Last Post: 01-02-2013, 05:32 AM
  2. Derived class doesn't see base class function
    By ejubenville in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2009, 01:56 PM
  3. class and giving in function or class problems ???
    By military genius in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2009, 08:34 AM
  4. call base class function or derived class function
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 05:23 AM
  5. Replies: 2
    Last Post: 04-06-2005, 07:25 AM