Thanks for the help guys. I have started work on this program again after a busy week of other commitments. Using your advice, I have cleared up most of the problems. The program is a realtime strategy game. Hence there are many functions within the "unit" class for making that unit interact with other units in the game. This is why there are so many functions that take a reference to the target unit (the target of an attack command or whatever).
There is one problem I still can't figure out though. I will post some of the relevant code, cutting out stuff thats not related to the problem to keep it short. Below I will list the compiler error. I know its a lot of code to look through but I could really use some help. Thanks.
Code:
struct UnitType {
char name[20];
int buildTime, finishedTime, mineralCost, vespeneCost, supplyCost, supplyProvided, typeID, minCollectRate, vespCollectRate;
};
Code:
class Unit {
public:
UnitType type;
int startTime, finishedTime, deathTime, tempState, currState, ID, builtFromID;
Unit(int start, int builtfromID, UnitType& tp);
};
Code:
Unit::Unit(int start, int builtfromID, UnitType& tp) {
startTime=start; builtFromID=builtfromID; type=tp;
finishedTime = startTime+tp.buildTime;
}
Code:
class UnitCollection {
public:
UnitType* theTypes;
Unit units[100];
int numUnits;
void addUnit(int starttime, int builtfromID, UnitType& type);
UnitCollection(UnitType* theUnitTypes);
};
Code:
void UnitCollection::addUnit(int starttime, int builtfromID, UnitType& type) {
Unit theUnit(starttime, builtfromID, type);
theUnit.currState = 0;
units[numUnits] = theUnit;
// theUnit=NULL;
numUnits++;
}
Code:
UnitCollection::UnitCollection(UnitType* theUnitTypes) {
theTypes = theUnitTypes;
numUnits=0;
addUnit(theTypes[0].buildTime, 0, theTypes[0]);
}
The compiler (Dev-Cpp) gives the following errors:
Code:
In constructor `UnitCollection::UnitCollection(UnitType*)':
no matching function for call to `Unit::Unit()'
candidates are: Unit::Unit(const Unit&)
Unit::Unit(int, int, UnitType&)
[Build Error] [UnitCollection.o] Error 1
Which is weird, because the "Unit" constructor is never called in the "UnitCollection" constructor. Granted, the addUnit function is called, which in turn calls the "Unit" constructor, but it doesn't try to call "Unit::Unit()", it provides the proper arguments. Anyway, this is the only error left after the help you provided earlier, Id really like to get it fixed. Sorry for digging up a thread that may have fallen off the first page. In the future should I make a new one? Thanks again guys!