Ahhh! My program refuses to work. I'm using string.h becuz it makes life so much easier, but at compile time, my program has an exception and the debugger brings up xstring.h and points to some junk. I've had strings work before.....but now it dont wanna work. I hate c++, it's so volatile, friggen link errors here, exceptions there. Then you copy the code and paste it into a new c++ file and it works. It's like what the heck? Anyway, if i can just get this demo program for a friend to work, id be content for a few days (untill i try to do something else and c++ messes up). Heres my program:
#include <iostream.h>
#include <stdlib.h>
#include <string>
using namespace std;
const int c_maxDogs = 25;
//-------------------id holder-----------------
struct id{
int idNum;
int idPos;
};
//--------------Object Class Definition----------------
class object{
public:
string className; //string identifying object type
id id; //Id used to identify object within the objectHandler
object(); //Constructor
};
//Constructor definition
object:
bject(){
}
//--------------Dog Class Definition--------------------
class dog
ublic object{
public:
string name; //name of dog
float weight; //weight of dog
int age; //age of dog
string breed; //breed of dog
bool sex; //sex of dog, 0 male, 1 female
dog(); //Constructor
void bark(); //Makes dog bark
};
//Constructor definition
dog::dog(){
weight = 0;
age = 0;
sex = 0;
className = "dog";
}
//Bark definition
void dog::bark(){
printf("Bark!"
;
}
//----------------Object Handler Defintion--------------------
class dogHandler{
public:
dog dogList [c_maxDogs]; //array to hold actual objects
id idList [c_maxDogs]; //array to keep track of object id's
int curId; //current id to assign
int count; //number of objects currently added
objectHandler(); //constructor
id generateId(); //generates id
void addObject(dog obj); //adds an object to handler
};
dogHandler:
bjectHandler(){
curId = 0;
count = 0;
}
id dogHandler::generateId(){
id tmpId;
tmpId.idNum = curId;
tmpId.idPos = count;
curId++;
return tmpId;
}
void dogHandler::addObject(dog obj){
if (count <= c_maxDogs){
id tId = generateId();
obj.id = tId;
dogList[count] = obj;
idList[count] = tId;
count++;
}
}
//---------------Finally, the test---------------------------
void main(){
dogHandler dogHnd;
dog tmpDog;
tmpDog.age = 3;
tmpDog.breed = "Collie";
tmpDog.name = "Lassie";
tmpDog.sex = 1;
tmpDog.weight = 50;
dogHnd.addObject(tmpDog);
dogHnd.dogList[0].bark();
system("pause"
;
}
#include <iostream.h>
#include <stdlib.h>
#include <string>
using namespace std;
const int c_maxDogs = 25;
//-------------------id holder-----------------
struct id{
int idNum;
int idPos;
};
//--------------Object Class Definition----------------
class object{
public:
string className; //string identifying object type
id id; //Id used to identify object within the objectHandler
object(); //Constructor
};
//Constructor definition
object:
}
//--------------Dog Class Definition--------------------
class dog
public:
string name; //name of dog
float weight; //weight of dog
int age; //age of dog
string breed; //breed of dog
bool sex; //sex of dog, 0 male, 1 female
dog(); //Constructor
void bark(); //Makes dog bark
};
//Constructor definition
dog::dog(){
weight = 0;
age = 0;
sex = 0;
className = "dog";
}
//Bark definition
void dog::bark(){
printf("Bark!"
}
//----------------Object Handler Defintion--------------------
class dogHandler{
public:
dog dogList [c_maxDogs]; //array to hold actual objects
id idList [c_maxDogs]; //array to keep track of object id's
int curId; //current id to assign
int count; //number of objects currently added
objectHandler(); //constructor
id generateId(); //generates id
void addObject(dog obj); //adds an object to handler
};
dogHandler:
curId = 0;
count = 0;
}
id dogHandler::generateId(){
id tmpId;
tmpId.idNum = curId;
tmpId.idPos = count;
curId++;
return tmpId;
}
void dogHandler::addObject(dog obj){
if (count <= c_maxDogs){
id tId = generateId();
obj.id = tId;
dogList[count] = obj;
idList[count] = tId;
count++;
}
}
//---------------Finally, the test---------------------------
void main(){
dogHandler dogHnd;
dog tmpDog;
tmpDog.age = 3;
tmpDog.breed = "Collie";
tmpDog.name = "Lassie";
tmpDog.sex = 1;
tmpDog.weight = 50;
dogHnd.addObject(tmpDog);
dogHnd.dogList[0].bark();
system("pause"
}