Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C++ Problem

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


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?

Name: Anonymous 2010-12-20 18:31

Don't use C++.

Name: Anonymous 2010-12-20 18:33

>>2
You cannot always decide which language you have to work in...

Name: Anonymous 2010-12-20 18:36

>>3
You always have a choice.  Always!

Name: Anonymous 2010-12-20 18:37

>>4
Not really, I study CS and have to learn this language, problem solved now though, so self saging

Name: Anonymous 2010-12-20 18:38

>>5
CS is a useless pseudosicence. Better study SICP.

Name: Anonymous 2010-12-20 18:39

>>6
I got that in my first year, amazing book, we study scheme in year 1, C++ and asm in year 2

Name: Anonymous 2010-12-20 18:45

>>7
That is why all smart people (like Bill Gates and Steve Jobs) dont have completed university education.

Name: Anonymous 2010-12-20 19:10

>>6
CS isn't even a science! It's applied math!

Name: Anonymous 2010-12-20 19:39

>>9
math isnt even a science? agreed.

Name: Anonymous 2010-12-20 21:06

Read the fucking signature and/or realize that you are doing nothing.

Name: Anonymous 2010-12-21 5:46

>>11
Found out I used ofstream instead of istream some time ago, silly mistake

Don't change these.
Name: Email:
Entire Thread Thread List