Agghh! Well, I yet again have a problem that I cannot fiqure out. I just reorganized a struct into it's own file. The new file works quite well, but the old file has no dependance on the struct, yet it somehow killed itself. What do I do ta fix it?
Errors:
ompiler: Default compiler
Building Makefile: "C:\Dev-Cpp\projects\1\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\projects\1\Makefile.win" all
g++.exe -c Equipment.cpp -o Equipment.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"
In file included from Equipment.cpp:8:
item.h:19: error: `string' does not name a type
item.h:35: error: variable or field `Save' declared void
item.h:35: error: expected `;' before '(' token
item.h:37: error: expected `;' before '(' token
item.h:46: error: ISO C++ forbids declaration of `vector' with no type
item.h:46: error: expected `;' before '<' token
item.h:52: error: expected `,' or `...' before '&' token
item.h:52: error: ISO C++ forbids declaration of `string' with no type
item.h:56: error: expected `,' or `...' before '&' token
item.h:56: error: ISO C++ forbids declaration of `string' with no type
In file included from Equipment.cpp:9:
Equipment.h:32: error: variable or field `Save' declared void
Equipment.h:32: error: expected `;' before '(' token
Equipment.h:33: error: expected `;' before '(' token
Equipment.cpp:51: error: no `void tEquipment::Save(std::ostream&)' member function declared in class `tEquipment'
Equipment.cpp:63: error: no `bool tEquipment::Load(std::ifstream&)' member function declared in class `tEquipment'
make.exe: *** [Equipment.o] Error 1
Execution terminated
items.h
//Item structure .h
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
//This is the structure of an Item
//Created some time in march
//Austen Higgins-Cassidy
#ifndef _ITEM_H_
#define _ITEM_H_
struct tItem
{
string name;
int type;
int id;
int wieght;
int value;
int para1;
int val1;
int para2;
int val2;
bool key;
tItem();
~tItem();
tItem(const tItem& RHS);
void Save(ostream& fOut);
bool Load(ifstream& fIn);
};
class ItemsData
{
private:
vector<tItem> ItemDataBase;
public:
ItemsData();
~ItemsData();
bool LoadItems(const string& filename);
bool SaveItems(const std::string filename);
void DisplayItems();
void MakeItem(const string& iname, int iwieght, int ival, int type, bool key = false);
};
#endif
items.cpp
//Items cpp
//Expantions for items.h
//Austen Higgins-Cassidy
// 4/1/2006
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
#include "item.h"
ItemsData::ItemsData()
{
ItemDataBase.clear();
}
ItemsData::~ItemsData()
{
ItemDataBase.clear();
}
// Load items based on a filename and returns true or false of the
// success.
bool ItemsData::LoadItems(const string& filename)
{
ifstream fobj;
fobj.open(filename.c_str());
if(fobj.fail() || !fobj.is_open())
return false;
//clear IDB
ItemDataBase.clear();
bool done = false;
while(!done)
{
tItem temp;
done = !temp.Load(fobj);
if(!done)
{
ItemDataBase.push_back(temp);
string buf;
getline(fobj, buf, '\n');
}
}
fobj.close();
return true;
}
// Save all of the items but keep them in the vector
bool ItemsData::SaveItems(const std::string filename)
{
ofstream fptr;
fptr.open(filename.c_str());
if(fptr.fail() || !fptr.is_open())
return false;
for(size_t x = 0; x < ItemDataBase.size(); x++)
{
ItemDataBase[x].Save(fptr);
}
fptr.close();
return true;
}
void ItemsData::DisplayItems()
{
for(size_t x = 0; x < ItemDataBase.size(); x++)
{
ItemDataBase[x].Save(cout);
cout << endl;
}
}
void ItemsData::MakeItem(const string& iname, int iwieght, int ival, int type, bool key)
{
tItem nItem;
nItem.id = 1+(int)ItemDataBase.size();
nItem.name = iname;
nItem.wieght = iwieght;
nItem.value = ival;
nItem.type = type;
nItem.key = key;
ItemDataBase.push_back(nItem);
}
tItem::tItem()
{
name.clear();
type = 0;
id = -1;
wieght = 0;
value = 0;
para1 = 0;
val1 = 0;
para2 = 0;
val2 = 0;
key = 0;
}
// We make a default destructor due to the C++ rule of 3
tItem::~tItem()
{
// Nothing to do
}
// We make a copy constructor due to the C++ rule of 3
tItem::tItem(const tItem& RHS)
{
name = RHS.name;
type = RHS.type;
while(id <= RHS.id)
{
srand(time(0));
id = rand();
}
wieght = RHS.wieght;
value = RHS.value;
para1 = RHS.para1;
val1 = RHS.val1;
para2 = RHS.para2;
val2 = RHS.val2;
key = RHS.key;
}
// For now, when you are developing your game or whatever, it is
// IMPORTANT to make sure that you know the file being written to
// files is clear, concise, and correct! Because of this, you will
// always want to save your data in text format so you can easily
// verify and validate it. When you take this approach, you can
// easily see if there is a bug in your code or in the data files
void tItem::Save(ostream& fOut)
{
fOut << name << endl;
fOut << type << " ";
fOut << id << " ";
fOut << wieght << " ";
fOut << value << " ";
fOut << para1 << " ";
fOut << val1 << " ";
fOut << para2 << " ";
fOut << val2 << " ";
fOut << key << endl;
}
// Same as what I said for the save function. When you are ready for
// deployment, you can make a new Save/Load function that will work
// in binary format. But for now, use text =)
// I also made this a bool to make sure we can load data from the file
bool tItem::Load(ifstream& fIn)
{
if(!getline(fIn, name))
return false;
fIn >> type;
fIn >> id;
fIn >> wieght;
fIn >> value;
fIn >> para1;
fIn >> val1;
fIn >> para2;
fIn >> val2;
fIn >> key;
return true;
}
Equipment.h (the new file)
//Equipment.h
//This file will initilize the equipment object
//It was originally in item.h, but I need to make use of the objects in that, and this was simpler.
//Austen Higgins-Cassidy
// 4/3/2006
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "item.h"
#ifndef _EQUIPMENT_H_
#define _EQUIPMENT_H_
struct tEquipment
{
tItem *head;
tItem *body;
tItem *rarm;
tItem *larm;
tItem *rhand;
tItem *lhand;
tItem *boots;
tItem *acc;
tEquipment();
~tEquipment();
tEquipment(const tEquipment& RHS);
void Save(ostream& fOut);
bool Load(ifstream& fIn);
};
#endif
and finally Equipment.cpp
//Expantion file for Equipment.h
//Austen Higgins-Cassidy
// 4/3/2006
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "item.h"
#include "Equipment.h"
using namespace std;
tEquipment::tEquipment()
{
head = NULL;
body = NULL;
rarm = NULL;
larm = NULL;
lhand = NULL;
rhand = NULL;
boots = NULL;
acc = NULL;
}
tEquipment::~tEquipment()
{
delete head;
delete body;
delete rarm;
delete larm;
delete lhand;
delete rhand;
delete boots;
delete acc;
}
tEquipment::tEquipment(const tEquipment &RHS)
{
head = RHS.head;
body = RHS.body;
rarm = RHS.rarm;
larm = RHS.larm;
lhand = RHS.lhand;
rhand = RHS.rhand;
boots = RHS.boots;
acc = RHS.acc;
}
void tEquipment::Save(ostream& fOut)
{
fOut << head->id << " ";
fOut << body->id << " ";
fOut << rarm->id << " ";
fOut << larm->id << " ";
fOut << rhand->id << " ";
fOut << lhand->id << " ";
fOut << boots->id<< " ";
fOut << acc->id << endl;
}
bool tEquipment::Load(ifstream& fIn)
{
int idtag;
head = NULL;
body = NULL;
rarm = NULL;
larm = NULL;
rhand = NULL;
lhand = NULL;
boots = NULL;
acc = NULL;
return true;
}
Thank you for helping me out.... I should know how to fix this, since I have had errors like this sooo many times.... but it seems something different creates that same error again and again.... :/
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be