|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I'm making a program and everything works except for a couple of
assignment operators for a string object. here is the snippet of code: name.assign(theItem.getName); I've also tried useing the "=" operator, but it doesn't compile. If anyone has any suggestions, I would appreciate the Thank you |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
InsainFreak101@gmail.com wrote:
> I'm making a program and everything works except for a couple of > assignment operators for a string object. > > here is the snippet of code: > > name.assign(theItem.getName); > > I've also tried useing the "=" operator, but it doesn't compile. > If anyone has any suggestions, I would appreciate the Just guessing, since you did not post much code: name = theItem.getName(); Best Kai-Uwe Bux |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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)); } |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
InsainFreak101@gmail.com wrote:
> I'm making a program and everything works except for a couple of > assignment operators for a string object. > > here is the snippet of code: > > name.assign(theItem.getName); > > I've also tried useing the "=" operator, but it doesn't compile. > If anyone has any suggestions, I would appreciate the Looking at the code you snipped I dont' see any getName other than that like, but I presume it's supposed to be a fuction. So would be: name.assign(theItem.getName()); or name = the Item.getName(); It is hard to say, however, since you are not showing the declaration of the class item, I just presume it has a method (function) called getName that either returns a string or a const reference to a string. If it doesn't, show more code. -- Jim Langston tazmaster@rocketmail.com |
|
![]() |
| Outils de la discussion | |
|
|