Afficher un message
Vieux 22/02/2008, 05h06   #3
InsainFreak101@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: String assignment operator


if it s, here is the whole class:
//I marked the faulty lines

#include <iostream>

#include <string>

#include <vector>

#include "item.h"

using namespace std;



class inventory

{

public:

void getInventory();

void addItem(item addItem, inventory inventory1);

void subtractItem(item subItem);

bool checkInventory();

void Equip(weapon Item, inventory inventory1);

void Unequip();

private:

vector<item> m_inventory;

vector<weapon> m_equiped;

};

//defining Inventory.getinventory function

void inventory::getInventory()

{

string name;

item theItem;

cout<<"here are your items:"<<endl;

for (int i=0; i<m_inventory.size(); ++i)

{

theItem = m_inventory[i];

name.clear();

name.assign(theItem.getName); //the assignment operator on
this line dosn't work

cout<<name<<endl;

}

cout<<"here are you equiped items:"<<endl;

for (int j=0; j<m_equiped.size(); ++j)

{

theItem = m_inventory[j];

name.clear();

name.assign(theItem.getName); //the assignment operator on
this line dosn't work

cout<<name<<endl;

}

}

//defining Inventory.addInventory function

void inventory::addItem(item addItem, inventory inventory1)

{

if (inventory1.checkInventory())

{

m_inventory.push_back(addItem);

}

else

cout<<"your inventory is full, discard some Items,";

cout<<" please discard some items and try again."<<endl;



}

//defining Inventory.subtractInventory function

void inventory::subtractItem(item subItem)

{

int i=0;

string name;

string compare;

name.assign(subItem.getName); //the assignment operator on this
line dosn't work

compare.assign(m_inventory[0].getName); //the assignment operator
on this line dosn't work

while (name!=compare)

{

++i;

compare.assign(m_inventory[i].getName); //the assignment
operator on this line dosn't work.

}

m_inventory.erase((m_inventory.begin()+i));

}

//defining Inventory.checkInventory function

bool inventory::checkInventory()

{

int i=0;

bool answer;



i = m_inventory.size();



if (i<10)

{

answer = true;

return answer;

}

if (i>=10)

{

answer = false;

return answer;

}

}



void inventory::Equip(weapon Item, inventory inventory1)

{

if (m_equiped.size()>0)

inventory1.Unequip();



m_equiped.push_back(Item);

}



void inventory::Unequip()

{

item Item;

Item = m_equiped[0];

m_equiped.erase((m_equiped.begin()+0));

}

  Réponse avec citation
 
Page generated in 0,06360 seconds with 9 queries