<?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[Konstruktorcode wird ignoriert]]></title><description><![CDATA[<p>Hi, ich habe 2 Objekte von 2 verschiedenen Klassen die eine wird im Konstruktor der anderen erstellt.<br />
das ganze sieht so aus:</p>
<pre><code class="language-cpp">Map::Map(int mapWidth, int mapHeight, int tileWidth, int tileHeight, Tileset* tileset, bf::path projectPath) : mapWidth(mapWidth), 
  mapHeight(mapHeight), tileWidth(tileWidth), tileHeight(tileHeight), tileset(NULL)
  {
  tileset = new shared::Tileset(bf::path(&quot;C:/Main/Tools/RMXP/RTP/Graphics/Tilesets/001-Grassland01.png&quot;), projectPath);
  }
</code></pre>
<p>Im source, der Header sieht so aus:</p>
<pre><code class="language-cpp">class Map
    {
    public:
      Map(int mapWidth, int mapHeight, int tileWidth, int tileHeight, Tileset* tileset, bf::path);
      ~Map();

      //Accessors
      void SetMapSize(int mapWidth, int mapHeight){this-&gt;mapWidth = mapWidth, this-&gt;mapHeight = mapHeight;}
      void GetMapSize(int&amp; mapWidth, int&amp; mapHeight){mapWidth = this-&gt;mapWidth, mapHeight = this-&gt;mapHeight;}
      int GetMapWidth() const {return mapWidth;}
      int GetMapHeight() const {return mapHeight;}
      int GetMapWidthInPx()const {return mapWidth * tileWidth;}
      int GetMapHeightInPx() const {return mapHeight * tileHeight;}

      void SetTileSize(int tileWidth, int tileHeight){this-&gt;tileWidth = tileWidth, this-&gt;tileHeight = tileHeight;}
      void GetTileSize(int&amp; tileWidth, int&amp; tileHeight) const {tileWidth = this-&gt;tileWidth, tileHeight = this-&gt;tileHeight;}
      int GetTileWidth() const {return tileWidth;}
      int GetTileHeight() const {return tileHeight;}

      void SetTileset(Tileset* tileset){this-&gt;tileset = tileset;}
      const Tileset* GetTileset() const {return tileset;}

    private:
      int mapWidth, mapHeight; //In tiles
      int tileWidth, tileHeight; //In pixels

      Tileset* tileset; 
    };
</code></pre>
<p>Erstellt wird das Objekt wie folgt:</p>
<pre><code class="language-cpp">mp = boost::shared_ptr&lt;shared::Map&gt;(new shared::Map(20, 15, 32, 32, NULL, CONFIGURATION-&gt;GetProjectPath()));
</code></pre>
<p>Wenn ich den Debugger frage zeigt tileset am Ende des Konstruktors korrekt auf das Objekt, aber wenn ich den Debugger direkt nach dem Konstruktor(also nach dem mp = boost::shared_ptr u.s.w.) zeigt tileset auf NULL, alle anderen Dinge sind korrekt, da stellt sich mir doch die Frage...<br />
warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/209034/konstruktorcode-wird-ignoriert</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 13:26:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/209034.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Mar 2008 22:48:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Konstruktorcode wird ignoriert on Tue, 25 Mar 2008 22:48:45 GMT]]></title><description><![CDATA[<p>Hi, ich habe 2 Objekte von 2 verschiedenen Klassen die eine wird im Konstruktor der anderen erstellt.<br />
das ganze sieht so aus:</p>
<pre><code class="language-cpp">Map::Map(int mapWidth, int mapHeight, int tileWidth, int tileHeight, Tileset* tileset, bf::path projectPath) : mapWidth(mapWidth), 
  mapHeight(mapHeight), tileWidth(tileWidth), tileHeight(tileHeight), tileset(NULL)
  {
  tileset = new shared::Tileset(bf::path(&quot;C:/Main/Tools/RMXP/RTP/Graphics/Tilesets/001-Grassland01.png&quot;), projectPath);
  }
</code></pre>
<p>Im source, der Header sieht so aus:</p>
<pre><code class="language-cpp">class Map
    {
    public:
      Map(int mapWidth, int mapHeight, int tileWidth, int tileHeight, Tileset* tileset, bf::path);
      ~Map();

      //Accessors
      void SetMapSize(int mapWidth, int mapHeight){this-&gt;mapWidth = mapWidth, this-&gt;mapHeight = mapHeight;}
      void GetMapSize(int&amp; mapWidth, int&amp; mapHeight){mapWidth = this-&gt;mapWidth, mapHeight = this-&gt;mapHeight;}
      int GetMapWidth() const {return mapWidth;}
      int GetMapHeight() const {return mapHeight;}
      int GetMapWidthInPx()const {return mapWidth * tileWidth;}
      int GetMapHeightInPx() const {return mapHeight * tileHeight;}

      void SetTileSize(int tileWidth, int tileHeight){this-&gt;tileWidth = tileWidth, this-&gt;tileHeight = tileHeight;}
      void GetTileSize(int&amp; tileWidth, int&amp; tileHeight) const {tileWidth = this-&gt;tileWidth, tileHeight = this-&gt;tileHeight;}
      int GetTileWidth() const {return tileWidth;}
      int GetTileHeight() const {return tileHeight;}

      void SetTileset(Tileset* tileset){this-&gt;tileset = tileset;}
      const Tileset* GetTileset() const {return tileset;}

    private:
      int mapWidth, mapHeight; //In tiles
      int tileWidth, tileHeight; //In pixels

      Tileset* tileset; 
    };
</code></pre>
<p>Erstellt wird das Objekt wie folgt:</p>
<pre><code class="language-cpp">mp = boost::shared_ptr&lt;shared::Map&gt;(new shared::Map(20, 15, 32, 32, NULL, CONFIGURATION-&gt;GetProjectPath()));
</code></pre>
<p>Wenn ich den Debugger frage zeigt tileset am Ende des Konstruktors korrekt auf das Objekt, aber wenn ich den Debugger direkt nach dem Konstruktor(also nach dem mp = boost::shared_ptr u.s.w.) zeigt tileset auf NULL, alle anderen Dinge sind korrekt, da stellt sich mir doch die Frage...<br />
warum?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480374</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480374</guid><dc:creator><![CDATA[JustAnotherNoob]]></dc:creator><pubDate>Tue, 25 Mar 2008 22:48:45 GMT</pubDate></item><item><title><![CDATA[Reply to Konstruktorcode wird ignoriert on Tue, 25 Mar 2008 23:28:01 GMT]]></title><description><![CDATA[<p>JustAnotherNoob schrieb:</p>
<blockquote>
<pre><code class="language-cpp">Map::Map(int mapWidth, int mapHeight, int tileWidth, int tileHeight, Tileset* tileset, bf::path projectPath) : mapWidth(mapWidth), 
  mapHeight(mapHeight), tileWidth(tileWidth), tileHeight(tileHeight), tileset(NULL)
  {
  tileset = new shared::Tileset(bf::path(&quot;C:/Main/Tools/RMXP/RTP/Graphics/Tilesets/001-Grassland01.png&quot;), projectPath);
  }
</code></pre>
</blockquote>
<p>tileset ist bei dir sowohl eine member-variable als auch ein argument für den konstruktor. das new bezieht sich auf dieses argument und nicht auf die member-variable.</p>
<p>da tileset keine referenz, sondern eine lokale kopie eines pointers ist und nur innerhalb des konstruktors lebt, kannst du nach dem konstruktoraufruf nicht mehr darauf zugreifen, weil die adresse 'verloren' geht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480383</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480383</guid><dc:creator><![CDATA[checka²]]></dc:creator><pubDate>Tue, 25 Mar 2008 23:28:01 GMT</pubDate></item><item><title><![CDATA[Reply to Konstruktorcode wird ignoriert on Tue, 25 Mar 2008 23:34:26 GMT]]></title><description><![CDATA[<p>Wah scheiße du hast Recht, das hab ich gar net gesehen.<br />
Ich bin zwar jetzt wieder beim Fehler davor-.- aber danke soweit...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480385</guid><dc:creator><![CDATA[JustAnotherNoob]]></dc:creator><pubDate>Tue, 25 Mar 2008 23:34:26 GMT</pubDate></item><item><title><![CDATA[Reply to Konstruktorcode wird ignoriert on Wed, 26 Mar 2008 06:01:23 GMT]]></title><description><![CDATA[<p>mach this-&gt;tileset draus im Ctor-Rumpf, dann sollte es klappen. Allerdings frag ich mich warum du ein tileset pointer als Argument übergibst wenn du es nicht benutzt...<br />
Und wenn wir schon dabei sind: da du eh mit shared_ptr arbeitest, wäre es eventuell sinnvoll, den tileset member auch davon profitieren zu lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480408</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 26 Mar 2008 06:01:23 GMT</pubDate></item><item><title><![CDATA[Reply to Konstruktorcode wird ignoriert on Wed, 26 Mar 2008 12:09:38 GMT]]></title><description><![CDATA[<blockquote>
<p>mach this-&gt;tileset draus im Ctor-Rumpf</p>
</blockquote>
<p>Darauf bin ich auch noch gekommen.<br />
Allerdings habe ich ein Problem beim löschen eines sf::Images in diesem Tileset (Accessviolation, egal ob Raw-, Smart- oder gar kein Pointer) und versuche verzweifelt die Ursache dafür zu finden</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1480560</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1480560</guid><dc:creator><![CDATA[JustAnotherNoob]]></dc:creator><pubDate>Wed, 26 Mar 2008 12:09:38 GMT</pubDate></item></channel></rss>