Name: Anonymous 2010-12-20 18:22
Hey /prog/
While playing around with classes and writing to files I ran into a problem, I'm trying to obtain an item from a file, which I do with this code
Whenever I try to compile I keep on getting the same error though, The compiler sais he cannot find a match for the opperator >>, he only mentions one possible candidate, which is the declaration of the >> operator in my class, this is how it is implemented
That piece of code is a friend of the item class, so I really don't see what the problem is, anybody who could shed some light on this situation?
While playing around with classes and writing to files I ran into a problem, I'm trying to obtain an item from a file, which I do with this code
void load_backpack(character& theChar)
{
backpack inventory = theChar.inventory_;
list <item> potions = inventory.potions;
list <item> armor = inventory.armor;
list <item> weapons = inventory.weapons;
ofstream item_file;
item_file.open(ITEM_FILE, ios::in);
while (item_file.good())
{
item theItem;
item_file >> theItem;
if (theItem.type() == "A") armor.push_front(theItem);
if (theItem.type() == "W") weapons.push_front(theItem);
if (theItem.type() == "P") potions.push_front(theItem);
}
}Whenever I try to compile I keep on getting the same error though, The compiler sais he cannot find a match for the opperator >>, he only mentions one possible candidate, which is the declaration of the >> operator in my class, this is how it is implemented
istream& operator>> (istream& is, item theItem)
{
string contents, xdy, weight;
getline(is, contents);
theItem.type_ = (read_os_string(contents, true));
theItem.name_ = (read_os_string(contents));
theItem.description_ = (read_os_string(contents));
weight = (read_os_string(contents));
xdy = (read_os_string(contents));
theItem.effect_ = (read_os_string(contents));
theItem.weight_ = atoi(weight.c_str());
theItem.xdy_ = xdy;
theItem.xdice_ = atoi((xdy.substr(0, 1)).c_str());
theItem.ydice_ = atoi((xdy.substr(2, 3)).c_str());
return is;
}That piece of code is a friend of the item class, so I really don't see what the problem is, anybody who could shed some light on this situation?