Hilfeeeee!!!!
-
Allerunterste Schublade
-
hallo
poste den code, den du hast, wie jj schon sagte, oder gehe ins projekteforum und zahle geld für die arbeit, die andere leisten.
übrigens: wähle richtige topics, "hilfee" ist das bescheuerste, was du wählen konntest.
dir wird gut und gerne geholfen, wenn du dich ein wenig bemühst und anfängst, selber zu arbeiten.
so long
-
hallo
ich verstehe nicht was das problem ist warum ihr so ausflippt, werde das was ich gemacht habe auch mal zuschicken...
und closed und elise danke für eure netten beiträge.
john doe ich poste mal was ich gemacht habe
-
#include "Item.h"
#include "Player.h"
#include <iostream>
#include <string>using namespace std;
Item::Item()
{}Item::Item(string Iname,int Iweight):name(Iname),weight(Iweight)
{}Item::~Item()
{}bool Item::operator <(Item I)
{if(I.weight<weight)
{
return 1;
}
else
if(I.weight>weight){
return 0;
}}
void Item::print()
{cout<<"Name: "<<this->name<<"Gewicht: "<<this->weight;
}
/*ostream & operator<<(ostream& output, const Item& i)
{return output;
}*/
/*ostream& operator<<(ostream& os, const Item& in)
{
os<<in.name<<" "<<in.weight;
cout<<endl;
return os;
}
*/
-
#ifndef _Item_H
#define _Item_H#include <string>
using namespace std;
class Item
{
public:Item(string Iname,int Iweight);
~Item();
Item();
void print();
// friend ostream &operator<<(ostream&, const Item&);
bool operator<( Item I);//private:
string name;
int weight;};
#endif
-
#include "Player.h"
#include <string>
#include <iostream>using namespace std;
Player::~Player()
{}Player::Player()
{}
void Player::addItem(Item *i)
{inventory.push_front(i);
}
void Player::removeItem()
{
inventory.pop_front();}
void Player::showInventory()
{for (it= inventory.begin(); it !=inventory.end(); it++)
{
(*it)->print();
}}
-
#ifndef _Player_H
#define _Player_H
#include "Item.h"
#include <string>
#include <list>
using std::list;using namespace std;
class Player
{public:
Player();
~Player();
void addItem(Item *i);
void removeItem();
void showInventory();Item i;
list<Item> inventory;
list<Item*>::iterator it;private:
string name;
int currentWeight;
int maximumWeight;
};#endif
-
Oh da ist ja jemand ganz schlau.
Poste das alles in einem Beitrag und mit C++-Tags.
-
Die frage ist ob das inventory von Item* laut aufgabenstellung bei mir richtig realisiert ist, und die sortierung funktioniert auch nicht warum weiss ich nicht, habe die operatoren richtig überladen für die ausgabe aber irgendwie stimmt da was nicht
-
genau das ist mein problem gewesen:
dass du keinen code gepostet hast, und dich scheinbar ausruhen wolltest auf leute, die dir eine aufgabe lösen.aber geht ja
so long
-
#include "Item.h" #include "Player.h" #include <iostream> #include <string> //#include <list> //#include <algorithm> //#include <string> //#include <fstream> //using std::list; using namespace std; Item::Item() {} Item::Item(string Iname,int Iweight):name(Iname),weight(Iweight) {} Item::~Item() {} bool Item::operator <(Item I) { if(I.weight<weight) { return 1; } else if(I.weight>weight) { return 0; } } void Item::print() { cout<<"Name: "<<this->name<<"Gewicht: "<<this->weight; } /*ostream & operator<<(ostream& output, const Item& i) { return output; }*/ /*ostream& operator<<(ostream& os, const Item& in) { os<<in.name<<" "<<in.weight; cout<<endl; return os; } */ #ifndef _Item_H #define _Item_H //#include <list> //#include <algorithm> //#include <string> //#include <fstream> //using std::list; #include <string> using namespace std; class Item { public: Item(string Iname,int Iweight); ~Item(); Item(); void print(); // friend ostream &operator<<(ostream&, const Item&); bool operator<( Item I); //private: string name; int weight; }; #endif #include "Player.h" #include <string> #include <iostream> using namespace std; Player::~Player() {} Player::Player() { } void Player::addItem(Item *i) { inventory.push_front(i); } void Player::removeItem() { inventory.pop_front(); } void Player::showInventory() { for (it= inventory.begin(); it !=inventory.end(); it++) { (*it)->print(); } }
-
elise schrieb:
genau das ist mein problem gewesen:
dass du keinen code gepostet hast, und dich scheinbar ausruhen wolltest auf leute, die dir eine aufgabe lösen.aber geht ja
so long
achso schon verstanden.
ich will mich nicht ausruhen probiere die ganze zeit hin und her aber irgendwie funktionieren einige sachen nichtbin zum ertsen mal in so einem forum....
danke elise
-
Ein Punkt zur Beachtung:
Du hälst in Player eine List mit Pointern auf Inventory. Die musst du im
Destruktor von Player auch wieder (selbst) sauber abräumen, mit delete für jedes
einzelne Inventory, sonst gibts Speicherleichen.:xmas2:
mfg JJ
-
was ist, wenn die übergabe gleich ist?
bool Item::operator <(Item I) { return weight < I.weight; }
-
John Doe schrieb:
Ein Punkt zur Beachtung:
Du hälst in Player eine List mit Pointern auf Inventory. Die musst du im
Destruktor von Player auch wieder (selbst) sauber abräumen, mit delete für jedes
einzelne Inventory, sonst gibts Speicherleichen.:xmas2:
mfg JJ
danke john das mache ich mal gleich