<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Unverständliches Problem]]></title><description><![CDATA[<p>Kann man das überhaupt machen:</p>
<p>Items.h</p>
<pre><code class="language-cpp">class Slot
{
public:
	virtual void use() = 0;
};

class Potion : public Slot
{
public:
	Potion();
	~Potion();
	void use();

	Potion* bla;
};
</code></pre>
<p>Items.cpp</p>
<pre><code class="language-cpp">#include &quot;Items.h&quot;

//***ITEM CLASSES***//
Potion::Potion()
{
	bla = new Potion;
}
Potion::~Potion()
{
	delete bla;
}

void Potion::use()
{
	;
}
</code></pre>
<p>Wenn ich eine Instanz der Klasse erstelle, bricht das Programm mit &quot;Press any key to continue&quot; ab. Bei einem neueren Compiler bekomme ich ein Problem mit dem Speicher oder so.</p>
<p>Was passt da nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/138836/unverständliches-problem</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 07:15:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/138836.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Mar 2006 18:18:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unverständliches Problem on Wed, 01 Mar 2006 18:18:41 GMT]]></title><description><![CDATA[<p>Kann man das überhaupt machen:</p>
<p>Items.h</p>
<pre><code class="language-cpp">class Slot
{
public:
	virtual void use() = 0;
};

class Potion : public Slot
{
public:
	Potion();
	~Potion();
	void use();

	Potion* bla;
};
</code></pre>
<p>Items.cpp</p>
<pre><code class="language-cpp">#include &quot;Items.h&quot;

//***ITEM CLASSES***//
Potion::Potion()
{
	bla = new Potion;
}
Potion::~Potion()
{
	delete bla;
}

void Potion::use()
{
	;
}
</code></pre>
<p>Wenn ich eine Instanz der Klasse erstelle, bricht das Programm mit &quot;Press any key to continue&quot; ab. Bei einem neueren Compiler bekomme ich ein Problem mit dem Speicher oder so.</p>
<p>Was passt da nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006122</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006122</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Wed, 01 Mar 2006 18:18:41 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Wed, 01 Mar 2006 18:22:43 GMT]]></title><description><![CDATA[<p>Denk mal selbst nach:</p>
<pre><code class="language-cpp">Potion::Potion()
{
    bla = new Potion;
}
</code></pre>
<p>So du erstellst irgendwo ein Potion.<br />
Im Konstruktor wird ein Potion erstellt.<br />
Im Konstruktor des im Konstruktor erstellen Potion wird ein neues Potion erstellt.<br />
usw.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006126</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006126</guid><dc:creator><![CDATA[zocker]]></dc:creator><pubDate>Wed, 01 Mar 2006 18:22:43 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Wed, 01 Mar 2006 18:33:37 GMT]]></title><description><![CDATA[<p>Oh, ja ... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Nun gut, ich wollte jeweils einen Zeiger auf alle Items irgendwo speichern.</p>
<p>Wo könnte ich das noch machen, außer in der Klasse selbst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006132</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Wed, 01 Mar 2006 18:33:37 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Wed, 01 Mar 2006 20:47:32 GMT]]></title><description><![CDATA[<p>Items werden gewöhlich durch das Inventar verwaltet, also wäre eine Klassen Inventory nen guter Ansatzpunkt.<br />
Die Items könntest du zB in nem std::vector speichern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006196</guid><dc:creator><![CDATA[Any]]></dc:creator><pubDate>Wed, 01 Mar 2006 20:47:32 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Wed, 01 Mar 2006 21:33:50 GMT]]></title><description><![CDATA[<p>Ja, ich habe jetzt auch eine Klasse &quot;Inventory&quot;.<br />
Darf ich meinen gesamten Code hier posten, oder liest das sowieso keiner?</p>
<p>Ich würde nämlich gerne wissen, ob ich es (halbwegs) richtig gemacht habe.</p>
<p>(Funktionieren tut es ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006234</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Wed, 01 Mar 2006 21:33:50 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Wed, 01 Mar 2006 22:14:17 GMT]]></title><description><![CDATA[<p>darfst du ruhig posten .....<br />
lesen tuts auf jedenfall einer....</p>
<p>Mfg Shade37337</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006244</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006244</guid><dc:creator><![CDATA[branleb]]></dc:creator><pubDate>Wed, 01 Mar 2006 22:14:17 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Wed, 01 Mar 2006 22:56:02 GMT]]></title><description><![CDATA[<p>Jedenfalls habe ich eine Frage, und zwar möchte ich einer Memberfunktion &quot;addItem()&quot; einen Parameter übergeben, und zwar das jeweilige Item.<br />
Nur in slots[] kann ich keinen Zeiger vom Typ Slot speichern, da slots[] ein Klassenarray von Slot ist.<br />
Jetzt weiß ich nicht, wie ich das machen soll.<br />
Hier mal die Codes:</p>
<p><strong>main.cpp</strong></p>
<pre><code class="language-cpp">//***INCLUDES***//
#include &quot;main.h&quot;

//***MAIN FUNCTION***//
void main()
{	
	inventory.addItem();
	init();
	mainMenu();
}
</code></pre>
<p><strong>main .h</strong></p>
<pre><code class="language-cpp">#ifndef _MAIN_H_
#define _MAIN_H_

//***INCLUDES***//
#include &quot;functions.h&quot;

#endif _MAIN_H_
</code></pre>
<p><strong>functions.cpp</strong></p>
<pre><code class="language-cpp">//***INCLUDES***//
#include &quot;functions.h&quot;

//***FUNCTIONS***//
void init()
{
	std::cout &lt;&lt; &quot;* * * T E X T   A D V E N T U R E * * *&quot; &lt;&lt; std::endl &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;Wie soll der Held heissen?&quot; &lt;&lt; std::endl &lt;&lt; std::endl;

	std::string name;
	std::cin &gt;&gt; name;

	player.nameMe(name);

	std::cout &lt;&lt; std::endl &lt;&lt; &quot;Willkommen, &quot; &lt;&lt; player.name &lt;&lt; &quot;!&quot; &lt;&lt; std::endl;

	CLS;
}

void mainMenu()
{
	CLS;
	std::cout &lt;&lt; &quot;* * * H A U P T M E N U E * * *&quot; &lt;&lt; std::endl &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;S&gt; STATUS&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;I&gt; INVENTAR&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;H&gt; HAENDLER&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;B&gt; BEENDEN&quot; &lt;&lt; std::endl;

	char operation;
	std::cin &gt;&gt; operation;

	switch(operation)
	{
	case 'S':
	case 's':
		showStatus();
		break;
	case 'I':
	case 'i':
		showInventory();
		break;
	case 'H':
	case 'h':
		showTrade();
		break;
	case 'B':
	case 'b':
		endGame();
		break;
	default:
		std::cout &lt;&lt; &quot;Ungueltige Eingabe. Wiederholen!&quot; &lt;&lt; std::endl;
		Sleep(1000);
		mainMenu();
		break;
	}
}

void endGame()
{
	CLS;
}

void showStatus()
{
	CLS;
	std::cout &lt;&lt; &quot;* * * &quot; &lt;&lt; player.name &lt;&lt; &quot; * * *&quot; &lt;&lt; std::endl &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;Gesundheit: &quot; &lt;&lt; player.health_min &lt;&lt; &quot; / &quot; &lt;&lt; player.health_max &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;Mana: &quot; &lt;&lt; player.mana_min &lt;&lt; &quot; / &quot; &lt;&lt; player.mana_max &lt;&lt; std::endl &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;Gold: &quot; &lt;&lt; player.gold &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;Z&gt; ZURUECK&quot; &lt;&lt; std::endl;

	char operation;
	std::cin &gt;&gt; operation;

	switch(operation)
	{
	default:
		mainMenu();
		break;
	}
}

void showInventory()
{
	CLS;
	player.health_min = 0;
	std::cout &lt;&lt; &quot;* * * I N V E N T A R * * *&quot; &lt;&lt; std::endl &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;1. Slot: &quot; &lt;&lt; inventory.slots[0]-&gt;getName() &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;2. Slot: &quot; &lt;&lt; inventory.slots[1]-&gt;getName() &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;3. Slot: &quot; &lt;&lt; inventory.slots[2]-&gt;getName() &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;4. Slot: &quot; &lt;&lt; inventory.slots[3]-&gt;getName() &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;5. Slot: &quot; &lt;&lt; inventory.slots[4]-&gt;getName() &lt;&lt; std::endl &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;T&gt; TESTADD&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;B&gt; BENUETZEN&quot; &lt;&lt; std::endl;
	std::cout &lt;&lt; &quot;&lt;Z&gt; ZURUECK&quot; &lt;&lt; std::endl;

	char operation;
	short slot;
	std::cin &gt;&gt; operation;

	switch(operation)
	{
	case 'T':
	case 't':
		if(inventory.addItem())
			std::cout &lt;&lt; &quot;Hinzugefuegt!&quot; &lt;&lt; std::endl;
		else
			std::cout &lt;&lt; &quot;Inventar voll!&quot; &lt;&lt; std::endl;
		Sleep(1000);
		showInventory();
	case 'B':
	case 'b':
		std::cout &lt;&lt; &quot;Slot: &quot; &lt;&lt; std::endl;
		std::cin &gt;&gt; slot;
		if(inventory.useItem(slot-1))
			std::cout &lt;&lt; &quot;Gegenstand in Slot &quot; &lt;&lt; slot &lt;&lt; &quot; wurde benutzt!&quot; &lt;&lt; std::endl;
		else
			std::cout &lt;&lt; &quot;Gegenstand in Slot &quot; &lt;&lt; slot &lt;&lt; &quot; wurde nicht benutzt!&quot; &lt;&lt; std::endl;
		Sleep(1000);
		showInventory();
	default:
		mainMenu();
		break;
	}	
}

void showTrade()
{
	CLS;
	std::cout &lt;&lt; &quot;* * * HANDEL * * *&quot; &lt;&lt;std::endl &lt;&lt; std::endl;
}
</code></pre>
<p><strong>functions.h</strong></p>
<pre><code class="language-cpp">#ifndef _FUNCTIONS_H_
#define _FUNCTIONS_H_

//***INCLUDES***//
#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &quot;Player.h&quot;
#include &quot;Inventory.h&quot;

//***MACROS***//
#define CLS system(&quot;CLS&quot;)
#define BLUE SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0009);
#define BLUELINE SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0011);
#define NORMAL SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0007);
#define GREY SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0008);
#define GOLD SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0006);
#define TURK SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0003);
#define GREEN SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0002);

//***FUNCTIONS***//
void init();
void mainMenu();
void endGame();
void showStatus();
void showInventory();
void showTrade();

#endif _FUNCTIONS_H_
</code></pre>
<p><strong>Player.cpp</strong></p>
<pre><code class="language-cpp">//***INCLUDES***//
#include &quot;Player.h&quot;

//***GLOBAL***//
Player player;

//***CLASS PLAYER***//
Player::Player()
{
	health_min = 50;
	health_max = 100;
	mana_min = 50;
	mana_max = 50;
	gold = 100;
	slots = (5 - 1);
}

void Player::nameMe(std::string n)
{
	name = n;
}

void Player::addHealth(short health)
{
	health_min += health;
	if(health_min &gt; health_max)
		health_min = health_max;
}

void Player::addMana(short mana)
{
	mana_min += mana;
	if(mana_min &gt; mana_max)
		mana_min = mana_max;
}
</code></pre>
<p><strong>Player.h</strong></p>
<pre><code class="language-cpp">#ifndef _PLAYER_H_
#define _PLAYER_H_

//***INCLUDES***//
#include &lt;string&gt;

//***CLASS Player***//
class Player
{
public:
	Player();
	void nameMe(std::string);
	void addHealth(short);
	void addMana(short);

	std::string name;
	int health_min, health_max;
	int mana_min, mana_max;
	unsigned gold;
	unsigned short slots;
}; extern Player player;

#endif _PLAYER_H_
</code></pre>
<p><strong>items.cpp</strong></p>
<pre><code class="language-cpp">//***INCLUDES***//
#include &quot;Items.h&quot;

//***CLASS Slot***//
Slot::Slot()
{
	;
}
Slot::~Slot()
{
	;
}

//***CLASS Empty***//
Empty::Empty()
{
	name = &quot;Leer&quot;;
}
Empty::~Empty()
{
	;
}

bool Empty::use()
{
	return false;
}
std::string Empty::getName()
{
	return name;
}
bool Empty::isFull()
{
	return false;
}

//***ITEM CLASSES***//
LightPotion::LightPotion()
{
	name = &quot;Leichter Heiltrank&quot;;
}
LightPotion::~LightPotion()
{
	;
}

bool LightPotion::use()
{
	if(player.health_min == player.health_max)
	{
		return false;
	}
	else
	{
		player.addHealth(50);
		return true;
	}
}
std::string LightPotion::getName()
{
	return name;
}
bool LightPotion::isFull()
{
	return true;
}
</code></pre>
<p><strong>items.h</strong></p>
<pre><code class="language-cpp">#ifndef _ITEMS_H_
#define _ITEMS_H_

//***INCLUDES***//
#include &quot;Player.h&quot;

//***CLASS Slot***//
class Slot
{
public:
	Slot();
	~Slot();

	virtual bool use() = 0;
	virtual std::string getName() = 0;
	virtual bool isFull() = 0;
};

//***CLASS Empty***//
class Empty : public Slot
{
public:
	Empty();
	~Empty();

	bool use();
	std::string getName();
	bool isFull();

	std::string name;
};

//***ITEM CLASSES***//
class LightPotion : public Slot
{
public:
	LightPotion();
	~LightPotion();

	bool use();
	std::string getName();
	bool isFull();

	std::string name;
};

#endif _ITEMS_H_
</code></pre>
<p><strong>inventory.cpp</strong></p>
<pre><code class="language-cpp">//***INCLUDES***//
#include &quot;Inventory.h&quot;

//***GLOBAL***//
Inventory inventory;

//***CLASS Inventory***//
Inventory::Inventory()
{
	empty = new Empty;

	slots = new Slot*[player.slots];
	slots[0] = empty;
	slots[1] = empty;
	slots[2] = empty;
	slots[3] = empty;
	slots[4] = empty;

	lightpotion = new LightPotion;
}
Inventory::~Inventory()
{
	delete slots;
	delete empty;

	delete lightpotion;
}

bool Inventory::addItem()
{
	for(int c = 0; c &lt;= 4; c++)
	{
		if(slots[c]-&gt;isFull())
			continue;
		else
		{
			slots[c] = lightpotion;
			return true;
		}
	}

	return false;
}
bool Inventory::useItem(short slot)
{
	if(slots[slot]-&gt;use())
	{
		slots[slot] = empty;
		return true;
	}
	else
		return false;
}
</code></pre>
<p><strong>inventory.h</strong></p>
<pre><code class="language-cpp">#ifndef _INVENTORY_H_
#define _INVENTORY_H_

//***INCLUDES***//
#include &quot;Items.h&quot;

//***CLASS Inventory***//
class Inventory
{
public:
	Inventory();
	~Inventory();

	bool addItem();
	bool useItem(short);

	Slot** slots;
	Empty* empty;

	LightPotion* lightpotion;
}; extern Inventory inventory;

#endif _INVENTORY_H_
</code></pre>
<p>Ich weiß, einiges ist noch zu verbessern.<br />
Zum Beispiel weiß ich nicht, wie ich statt einer Funktion isFull() nur ein Flag verwende, weil eine Variable kann ich nicht mit slots[]-&gt; ansprechen, nur eine Funktion.</p>
<p>Bin für alle Tipps dankbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>(Beim Aufruf von showInventory() wird player.health_min deshalb auf 0 gesetzt, damit man immer use() verwenden kann [geht nur, wenn player.health_min &lt; player.health_max]und somit das System testen kann)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006266</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Wed, 01 Mar 2006 22:56:02 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 00:25:43 GMT]]></title><description><![CDATA[<p>also.. ich hab deinen code noch nicht ganz gelesen aber :<br />
verwende referenzen und std::vector oder ähnliches und keine zeiger und arrays...<br />
mit denen handelst du dir nur bufferoverflows ein</p>
<p>Mfg Shade37337</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006293</guid><dc:creator><![CDATA[branleb]]></dc:creator><pubDate>Thu, 02 Mar 2006 00:25:43 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 00:31:09 GMT]]></title><description><![CDATA[<p>Ja, wenn ich es gelernt habe. Bis jetzt habe ich noch nicht einmal über Klassen gelernt und vererbe schon, also bin ich daweil stolz auf mich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Wenn ich dazulerne, werde ich auch versuchen, den Code zu optimieren.<br />
Ich finde man lernt am besten, wenn man probiert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006294</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Thu, 02 Mar 2006 00:31:09 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 07:05:52 GMT]]></title><description><![CDATA[<p>und noch etwas, member von klassen macht man Gewöhnlich private oder protected, damit eben soetwas:</p>
<pre><code class="language-cpp">std::cout &lt;&lt; &quot;* * * &quot; &lt;&lt; player.name &lt;&lt; &quot; * * *&quot; &lt;&lt; std::endl &lt;&lt; std::endl;
</code></pre>
<p>nicht funktionieren sollte!</p>
<p>man schreibt für soetwas eigentlich Methoden (Get Set Methoden), für den name die könnte so aussehen:</p>
<pre><code class="language-cpp">string GetName()const
{
 return name;
}
</code></pre>
<p>denn es sollte verhindert werden, das &quot;unbefugte&quot; auf die member zugreifen könnten!</p>
<p>so, ich les mir später dann noch weiter durch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006376</guid><dc:creator><![CDATA[ser1al]]></dc:creator><pubDate>Thu, 02 Mar 2006 07:05:52 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 07:32:30 GMT]]></title><description><![CDATA[<p>Hier noch mal ein paar weitere Anmerkungen:</p>
<p>- Der Rückgabetyp von main() ist int <strong>nicht</strong> void!</p>
<p>- Finger weg von dem #define - Krempel. Dazu gibt es in C++ inline.</p>
<p>- Wie schon gesagt, für das Array besser einen std::vector nehmen. Wenn man nicht ganz genau weiß, was man tut, kann man bei von Hand verwalteten Arrays fürchterlich viel falsch machen (in deinem Code ist z.B. einer der delete-Aufrufe falsch).</p>
<p>- Die ganzen losen Funktionen gefallen mir nicht. Das schreit doch geradezu danach eine Klasse (Game) daraus zu machen.</p>
<p>- Das Inventar gehört doch sicherlich zum Spieler, oder? Also sollte die Klasse Player neben Dingen wie Gold oder Mana auch ein Inventory haben.</p>
<pre><code class="language-cpp">class Player
{
public:
    Player();
    void nameMe(std::string);
    void addHealth(short);
    void addMana(short);

private:
    std::string name;
    int health_min, health_max;
    int mana_min, mana_max;
    unsigned gold;
    unsigned short slots;
    Inventory inventory;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1006388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006388</guid><dc:creator><![CDATA[Z2]]></dc:creator><pubDate>Thu, 02 Mar 2006 07:32:30 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 12:22:02 GMT]]></title><description><![CDATA[<p>Ich habe Inventory einfach extern definiert.<br />
Weil ich brauche ja nur eine einzige Instanz von Inventory.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006696</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006696</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Thu, 02 Mar 2006 12:22:02 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 12:39:31 GMT]]></title><description><![CDATA[<p>Solange du nur einen Spieler hast, ja. Aber eventuell willst du das Spiel irgendwann für Team-Play erweitern (oder die NPC's sollen auch in der LAge sein, Items einzusammeln und mitzuschleppen) - dann braucht doch wieder jeder Charakter sein eigenes Inventory.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006714</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 02 Mar 2006 12:39:31 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 12:59:35 GMT]]></title><description><![CDATA[<p>Und selbst wenn nicht ist extern (global) IMHO die am wenigsten Elegante Lösung des Problems <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006744</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006744</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 02 Mar 2006 12:59:35 GMT</pubDate></item><item><title><![CDATA[Reply to Unverständliches Problem on Thu, 02 Mar 2006 13:09:53 GMT]]></title><description><![CDATA[<p>Danke für die vielen Tipps!</p>
<p>Am besten gehe ich mein C++ Buch weiter durch, denn gleich an ein Projekt mit mehreren Klassen usw. zu wagen halte ich ja doch nicht für sinnvoll <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006763</guid><dc:creator><![CDATA[ceplusplus]]></dc:creator><pubDate>Thu, 02 Mar 2006 13:09:53 GMT</pubDate></item></channel></rss>