X
Xpyder
Hey - i am working on a project and have encountered a problem.
when i try to make a pointer in an object to hold the address of
another object it works fine - but the problem is when i try to access
data through that pointer - my code is as follows:
// Cunit 2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
class Cweapon
{
public:
int itsDamage;
int itsRange;
int itsRoF;
};
class Cmember
{
public:
int itsHealth;
int itsSID;
};
class Cstat
{
public:
int itsMaxHealth;
int itsArmour_Expl,
itsArmour_Proj,
itsArmour_Blad;
int itsLoS;
int itsSpeed;
int itsSize;
int itsAccuracy;
int itsMaxMembers;
int itsValue;
};
class Cunit
{
public:
Cstat* itsStat;
Cweapon* itsWeapon;
Cmember itsMember[3];
int itsUID;
};
Cunit Utroop[10];
Cstat Stroop;
Cweapon Wtroop;
int Utroop_ctr = 0;
int main()
{
Stroop.itsMaxHealth = 100;
Stroop.itsArmour_Expl = 100;
Stroop.itsArmour_Proj = 100;
Stroop.itsArmour_Blad = 100;
Stroop.itsLoS = 100;
Stroop.itsSpeed = 100;
Stroop.itsSize = 100;
Stroop.itsAccuracy = 100;
Stroop.itsMaxMembers = 5;
Stroop.itsValue = 1000;
Wtroop.itsDamage = 100;
Wtroop.itsRoF = 100;
Wtroop.itsRange = 100;
return 0;
// if (User clicks on "create TROOP"button)
Utroop[Utroop_ctr].itsStat = &Stroop;
Utroop[Utroop_ctr].itsWeapon = &Wtroop;
Utroop[Utroop_ctr].itsUID = Utroop[Utroop_ctr].itsStat.itsValue +
Utroop_ctr;
for (int i = 0;i < Utroop[Utroop_ctr].itsStat.itsMaxMembers;i++) //
this is where probs occur
Utroop[Utroop_ctr].itsMember.itsHealth =
Utroop[Utroop_ctr].itsStat.itsMaxHealth;
Utroop_ctr++;
return 0;
}
//////////////code dump//////////////////
/*
*/
i would appreciate it if anyone could help me out here
Xpy
when i try to make a pointer in an object to hold the address of
another object it works fine - but the problem is when i try to access
data through that pointer - my code is as follows:
// Cunit 2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
class Cweapon
{
public:
int itsDamage;
int itsRange;
int itsRoF;
};
class Cmember
{
public:
int itsHealth;
int itsSID;
};
class Cstat
{
public:
int itsMaxHealth;
int itsArmour_Expl,
itsArmour_Proj,
itsArmour_Blad;
int itsLoS;
int itsSpeed;
int itsSize;
int itsAccuracy;
int itsMaxMembers;
int itsValue;
};
class Cunit
{
public:
Cstat* itsStat;
Cweapon* itsWeapon;
Cmember itsMember[3];
int itsUID;
};
Cunit Utroop[10];
Cstat Stroop;
Cweapon Wtroop;
int Utroop_ctr = 0;
int main()
{
Stroop.itsMaxHealth = 100;
Stroop.itsArmour_Expl = 100;
Stroop.itsArmour_Proj = 100;
Stroop.itsArmour_Blad = 100;
Stroop.itsLoS = 100;
Stroop.itsSpeed = 100;
Stroop.itsSize = 100;
Stroop.itsAccuracy = 100;
Stroop.itsMaxMembers = 5;
Stroop.itsValue = 1000;
Wtroop.itsDamage = 100;
Wtroop.itsRoF = 100;
Wtroop.itsRange = 100;
return 0;
// if (User clicks on "create TROOP"button)
Utroop[Utroop_ctr].itsStat = &Stroop;
Utroop[Utroop_ctr].itsWeapon = &Wtroop;
Utroop[Utroop_ctr].itsUID = Utroop[Utroop_ctr].itsStat.itsValue +
Utroop_ctr;
for (int i = 0;i < Utroop[Utroop_ctr].itsStat.itsMaxMembers;i++) //
this is where probs occur
Utroop[Utroop_ctr].itsMember.itsHealth =
Utroop[Utroop_ctr].itsStat.itsMaxHealth;
Utroop_ctr++;
return 0;
}
//////////////code dump//////////////////
/*
*/
i would appreciate it if anyone could help me out here
Xpy