<?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[Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-(]]></title><description><![CDATA[<p>Hallo zusammen,<br />
bin recht neu im C++, hoffe aber bald ein Mitglied der Gemeinde zu werden:-)<br />
Meine Aufgabe derzeit ein XML File einzulesen und zu speichern.<br />
Leider klappt nicht alles so wie ich es mir vorgestellt habe.<br />
Anzahl der zu speichernden Objekte weißt man vor dem Parsen nicht.<br />
Daher hab ich ein Paar Fragen:<br />
Wie muss ich richtig dynamisch mehrere Objekte in einer Schleife erzeugen?<br />
mit new? mach ich das richtig?<br />
Ist die Liste der richtige Container um meine Objekte zu speichern?<br />
(ich muss später diese Liste nur komplett durchlaufen)<br />
<strong>Auf die privaten Elemente der Objekte (Junction) aus der Liste kann ich nicht zugreifen, aus dem Array schon, wo liegt das Problem?</strong><br />
warum wird die Größe des Arrays mit 20 angegeben obwohl ich 5 eingegeben habe?<br />
Wofür steht eine &quot;8&quot; im &quot;8Junction&quot; als Ausgabe für &quot;typeid ((*Iter)).name()&quot; oder typeid ((* array[ti])).name() ?<br />
was kann ich noch alles verbessern?<br />
Vielen Dank im voraus.</p>
<p>main.cpp</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#endif

#include &lt;libxml++-2.6/libxml++/libxml++.h&gt;
#include &lt;libxml++-2.6/libxml++/parsers/textreader.h&gt;

#include &lt;iostream&gt;
#include &lt;list&gt;
#include &lt;typeinfo&gt; // &lt;&lt; typeid(reader.get_value()).name() &lt;&lt;
#include &lt;boost/lexical_cast.hpp&gt;

#include &quot;Junction.h&quot;
using namespace std;

//ostream &amp; operator&lt;&lt;(ostream &amp;output, const Junction &amp; junc) {
//    output &lt;&lt; &quot;ID &quot; &lt;&lt; (int) junc.getID() &lt;&lt; endl; // &lt;&lt; ' ' &lt;&lt; junc.getX &lt;&lt; ' ' &lt;&lt; junc.getY;
//    return output;
//}

int main(int argc, char* argv[]) {

    list &lt;Junction&gt; JunctionList;
    list &lt;Junction&gt;::iterator Iter;

    Junction * array[5];
    int ai = 0;

    cout &lt;&lt; &quot;sizeof(array): &quot; &lt;&lt; sizeof (array) &lt;&lt; endl;
    try {
        xmlpp::TextReader reader(&quot;/home/sugarray21/sumo-0.11.1/maps/map_very_small.net&quot;);

        while (reader.read()) {
            if (reader.get_name() == &quot;junction&quot;) {
                int id;
                float x, y;
                cout &lt;&lt; &quot;--- junction ---&quot; &lt;&lt; endl;

                if (reader.has_attributes()) {
                    reader.move_to_first_attribute();
                    do {

                        if (reader.get_name() == &quot;id&quot;) {
                            id = boost::lexical_cast&lt;int&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  ID:: &quot; &lt;&lt; id &lt;&lt; endl;
                        } else if (reader.get_name() == &quot;x&quot;) {
                            x = boost::lexical_cast&lt;float&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  X :: &quot; &lt;&lt; x &lt;&lt; endl;
                        } else if (reader.get_name() == &quot;y&quot;) {
                            y = boost::lexical_cast&lt;float&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  Y :: &quot; &lt;&lt; y &lt;&lt; endl;
                        }

                    } while (reader.move_to_next_attribute());

                    cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; id &lt;&lt; &quot;: &quot; &lt;&lt; x &lt;&lt; &quot;: &quot; &lt;&lt; y &lt;&lt; endl;

                    Junction *t_Junction = new Junction(id, x, y);
                    cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; t_Junction-&gt;getID() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction-&gt;getX() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction-&gt;getY() &lt;&lt; endl;
                    JunctionList.push_back(*t_Junction);
                    array[ai++] = t_Junction;

                    // Junction t_Junction(id, x, y);
                    // cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; t_Junction.getID() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction.getX() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction.getY() &lt;&lt; endl;

                    reader.move_to_element();
                } else {
                }

            }

        }
    } catch (const exception&amp; e) {
        cout &lt;&lt; &quot;Exception caught: &quot; &lt;&lt; e.what() &lt;&lt; endl;
    }

    cout &lt;&lt; &quot;JunctionList.size: &quot; &lt;&lt; JunctionList.size() &lt;&lt; endl;
    for (Iter = JunctionList.begin(); Iter != JunctionList.end(); ++Iter) cout &lt;&lt; typeid ((*Iter)).name() &lt;&lt; &quot; &quot; &lt;&lt;  (*Iter).getID() &lt;&lt; &quot; &quot;; // print all
    cout &lt;&lt; endl;

    int ti;
    cout &lt;&lt; &quot;sizeof(array): &quot; &lt;&lt; sizeof (array) &lt;&lt; endl;
    for (ti = 0; ti&lt;sizeof (array); ti++) {
        cout &lt;&lt; typeid ((* array[ti])).name() &lt;&lt; &quot; ID: &quot; &lt;&lt; (* array[ti]).getID();
        cout &lt;&lt; &quot; X: &quot; &lt;&lt; (* array[ti]).getX() &lt;&lt; &quot; Y: &quot; &lt;&lt; (* array[ti]).getY() &lt;&lt; endl;
    }
}
</code></pre>
<p>junction.h</p>
<pre><code class="language-cpp">/* 
 * File:   Junction.h
 * Author: sugarray21
 *
 * Created on 12. Januar 2010, 15:40
 */

#ifndef _JUNCTION_H
#define	_JUNCTION_H

class Junction {
//    friend ostream &amp; operator&lt;&lt;(ostream &amp;, const Junction &amp;);

public:
    Junction();
    Junction(const Junction&amp; orig);
    Junction(int id, float x, float y);

    int getID();
    float getX();
    float getY();

    void setID(int id);
    void setX(float x);
    void setY(float y);

    virtual ~Junction();

private:
    unsigned int id;
    float x, y;

};

#endif	/* _JUNCTION_H */
</code></pre>
<p>junction.cpp</p>
<pre><code class="language-cpp">/* 
 * File:   Junction.cpp
 * Author: sugarray21
 * 
 * Created on 12. Januar 2010, 15:40
 */

#include &quot;Junction.h&quot;

Junction::Junction() {
}

Junction::Junction(const Junction&amp; orig) {
}

Junction::Junction(int t_id, float t_x, float t_y) {
    id = t_id;
    x = t_x;
    y = t_y;
}

Junction::~Junction() {
}

int Junction::getID() {
    return id;
};

float Junction::getX() {
    return x;
};

float Junction::getY() {
    return y;
};
</code></pre>
<p>Ausgabe:</p>
<pre><code>sizeof(array): 20
--- junction ---
  ID:: 317557901
  X :: 630.25
  Y :: 1697
Junction: 317557901: 630.25: 1697
Junction: 317557901: 630.25: 1697
--- junction ---
  ID:: 317558017
  X :: 644.22
  Y :: 952
Junction: 317558017: 644.22: 952
Junction: 317558017: 644.22: 952
--- junction ---
  ID:: 317558232
  X :: 414.62
  Y :: 0
Junction: 317558232: 414.62: 0
Junction: 317558232: 414.62: 0
--- junction ---
  ID:: 6350306
  X :: 0
  Y :: 1124.5
Junction: 6350306: 0: 1124.5
Junction: 6350306: 0: 1124.5
JunctionList.size: 4
8Junction 112 8Junction 112 8Junction 112 8Junction 112 
sizeof(array): 20
8Junction ID: 317557901 X: 630.25 Y: 1697
8Junction ID: 317558017 X: 644.22 Y: 952
8Junction ID: 317558232 X: 414.62 Y: 0
8Junction ID: 6350306 X: 0 Y: 1124.5
Segmentation fault
Press [Enter] to close the terminal ...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/258739/anfänger-xml-parsen-und-objekte-in-einer-liste-speichern-klappt-nicht</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 04:12:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/258739.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Jan 2010 14:55:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 14:55:06 GMT]]></title><description><![CDATA[<p>Hallo zusammen,<br />
bin recht neu im C++, hoffe aber bald ein Mitglied der Gemeinde zu werden:-)<br />
Meine Aufgabe derzeit ein XML File einzulesen und zu speichern.<br />
Leider klappt nicht alles so wie ich es mir vorgestellt habe.<br />
Anzahl der zu speichernden Objekte weißt man vor dem Parsen nicht.<br />
Daher hab ich ein Paar Fragen:<br />
Wie muss ich richtig dynamisch mehrere Objekte in einer Schleife erzeugen?<br />
mit new? mach ich das richtig?<br />
Ist die Liste der richtige Container um meine Objekte zu speichern?<br />
(ich muss später diese Liste nur komplett durchlaufen)<br />
<strong>Auf die privaten Elemente der Objekte (Junction) aus der Liste kann ich nicht zugreifen, aus dem Array schon, wo liegt das Problem?</strong><br />
warum wird die Größe des Arrays mit 20 angegeben obwohl ich 5 eingegeben habe?<br />
Wofür steht eine &quot;8&quot; im &quot;8Junction&quot; als Ausgabe für &quot;typeid ((*Iter)).name()&quot; oder typeid ((* array[ti])).name() ?<br />
was kann ich noch alles verbessern?<br />
Vielen Dank im voraus.</p>
<p>main.cpp</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#endif

#include &lt;libxml++-2.6/libxml++/libxml++.h&gt;
#include &lt;libxml++-2.6/libxml++/parsers/textreader.h&gt;

#include &lt;iostream&gt;
#include &lt;list&gt;
#include &lt;typeinfo&gt; // &lt;&lt; typeid(reader.get_value()).name() &lt;&lt;
#include &lt;boost/lexical_cast.hpp&gt;

#include &quot;Junction.h&quot;
using namespace std;

//ostream &amp; operator&lt;&lt;(ostream &amp;output, const Junction &amp; junc) {
//    output &lt;&lt; &quot;ID &quot; &lt;&lt; (int) junc.getID() &lt;&lt; endl; // &lt;&lt; ' ' &lt;&lt; junc.getX &lt;&lt; ' ' &lt;&lt; junc.getY;
//    return output;
//}

int main(int argc, char* argv[]) {

    list &lt;Junction&gt; JunctionList;
    list &lt;Junction&gt;::iterator Iter;

    Junction * array[5];
    int ai = 0;

    cout &lt;&lt; &quot;sizeof(array): &quot; &lt;&lt; sizeof (array) &lt;&lt; endl;
    try {
        xmlpp::TextReader reader(&quot;/home/sugarray21/sumo-0.11.1/maps/map_very_small.net&quot;);

        while (reader.read()) {
            if (reader.get_name() == &quot;junction&quot;) {
                int id;
                float x, y;
                cout &lt;&lt; &quot;--- junction ---&quot; &lt;&lt; endl;

                if (reader.has_attributes()) {
                    reader.move_to_first_attribute();
                    do {

                        if (reader.get_name() == &quot;id&quot;) {
                            id = boost::lexical_cast&lt;int&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  ID:: &quot; &lt;&lt; id &lt;&lt; endl;
                        } else if (reader.get_name() == &quot;x&quot;) {
                            x = boost::lexical_cast&lt;float&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  X :: &quot; &lt;&lt; x &lt;&lt; endl;
                        } else if (reader.get_name() == &quot;y&quot;) {
                            y = boost::lexical_cast&lt;float&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  Y :: &quot; &lt;&lt; y &lt;&lt; endl;
                        }

                    } while (reader.move_to_next_attribute());

                    cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; id &lt;&lt; &quot;: &quot; &lt;&lt; x &lt;&lt; &quot;: &quot; &lt;&lt; y &lt;&lt; endl;

                    Junction *t_Junction = new Junction(id, x, y);
                    cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; t_Junction-&gt;getID() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction-&gt;getX() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction-&gt;getY() &lt;&lt; endl;
                    JunctionList.push_back(*t_Junction);
                    array[ai++] = t_Junction;

                    // Junction t_Junction(id, x, y);
                    // cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; t_Junction.getID() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction.getX() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction.getY() &lt;&lt; endl;

                    reader.move_to_element();
                } else {
                }

            }

        }
    } catch (const exception&amp; e) {
        cout &lt;&lt; &quot;Exception caught: &quot; &lt;&lt; e.what() &lt;&lt; endl;
    }

    cout &lt;&lt; &quot;JunctionList.size: &quot; &lt;&lt; JunctionList.size() &lt;&lt; endl;
    for (Iter = JunctionList.begin(); Iter != JunctionList.end(); ++Iter) cout &lt;&lt; typeid ((*Iter)).name() &lt;&lt; &quot; &quot; &lt;&lt;  (*Iter).getID() &lt;&lt; &quot; &quot;; // print all
    cout &lt;&lt; endl;

    int ti;
    cout &lt;&lt; &quot;sizeof(array): &quot; &lt;&lt; sizeof (array) &lt;&lt; endl;
    for (ti = 0; ti&lt;sizeof (array); ti++) {
        cout &lt;&lt; typeid ((* array[ti])).name() &lt;&lt; &quot; ID: &quot; &lt;&lt; (* array[ti]).getID();
        cout &lt;&lt; &quot; X: &quot; &lt;&lt; (* array[ti]).getX() &lt;&lt; &quot; Y: &quot; &lt;&lt; (* array[ti]).getY() &lt;&lt; endl;
    }
}
</code></pre>
<p>junction.h</p>
<pre><code class="language-cpp">/* 
 * File:   Junction.h
 * Author: sugarray21
 *
 * Created on 12. Januar 2010, 15:40
 */

#ifndef _JUNCTION_H
#define	_JUNCTION_H

class Junction {
//    friend ostream &amp; operator&lt;&lt;(ostream &amp;, const Junction &amp;);

public:
    Junction();
    Junction(const Junction&amp; orig);
    Junction(int id, float x, float y);

    int getID();
    float getX();
    float getY();

    void setID(int id);
    void setX(float x);
    void setY(float y);

    virtual ~Junction();

private:
    unsigned int id;
    float x, y;

};

#endif	/* _JUNCTION_H */
</code></pre>
<p>junction.cpp</p>
<pre><code class="language-cpp">/* 
 * File:   Junction.cpp
 * Author: sugarray21
 * 
 * Created on 12. Januar 2010, 15:40
 */

#include &quot;Junction.h&quot;

Junction::Junction() {
}

Junction::Junction(const Junction&amp; orig) {
}

Junction::Junction(int t_id, float t_x, float t_y) {
    id = t_id;
    x = t_x;
    y = t_y;
}

Junction::~Junction() {
}

int Junction::getID() {
    return id;
};

float Junction::getX() {
    return x;
};

float Junction::getY() {
    return y;
};
</code></pre>
<p>Ausgabe:</p>
<pre><code>sizeof(array): 20
--- junction ---
  ID:: 317557901
  X :: 630.25
  Y :: 1697
Junction: 317557901: 630.25: 1697
Junction: 317557901: 630.25: 1697
--- junction ---
  ID:: 317558017
  X :: 644.22
  Y :: 952
Junction: 317558017: 644.22: 952
Junction: 317558017: 644.22: 952
--- junction ---
  ID:: 317558232
  X :: 414.62
  Y :: 0
Junction: 317558232: 414.62: 0
Junction: 317558232: 414.62: 0
--- junction ---
  ID:: 6350306
  X :: 0
  Y :: 1124.5
Junction: 6350306: 0: 1124.5
Junction: 6350306: 0: 1124.5
JunctionList.size: 4
8Junction 112 8Junction 112 8Junction 112 8Junction 112 
sizeof(array): 20
8Junction ID: 317557901 X: 630.25 Y: 1697
8Junction ID: 317558017 X: 644.22 Y: 952
8Junction ID: 317558232 X: 414.62 Y: 0
8Junction ID: 6350306 X: 0 Y: 1124.5
Segmentation fault
Press [Enter] to close the terminal ...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1838850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838850</guid><dc:creator><![CDATA[sugarray21]]></dc:creator><pubDate>Thu, 14 Jan 2010 14:55:06 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 15:14:43 GMT]]></title><description><![CDATA[<p>sugarray21 schrieb:</p>
<blockquote>
<p>Wie muss ich richtig dynamisch mehrere Objekte in einer Schleife erzeugen?<br />
mit new? mach ich das richtig?</p>
</blockquote>
<p>Nein, benutz einfach direkt die Einfügeoperationen des Containers.</p>
<blockquote>
<p>Ist die Liste der richtige Container um meine Objekte zu speichern?<br />
(ich muss später diese Liste nur komplett durchlaufen)</p>
</blockquote>
<p>Für den Zweck ist der Containertyp relativ egal. vector dürfte deiner Beschreibung nach aber ein wenig besser geeignet sein.</p>
<blockquote>
<p><strong>Auf die privaten Elemente der Objekte (Junction) aus der Liste kann ich nicht zugreifen, aus dem Array schon, wo liegt das Problem?</strong></p>
</blockquote>
<p>Naja, das ist halt der Zweck von private <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="😉"
    /> . Wo bitte greifst du über das Array auf private Elemente zu? Ich kann die Stelle nicht finden. Das dürfte eigentlich nicht gehen.</p>
<blockquote>
<p>warum wird die Größe des Arrays mit 20 angegeben obwohl ich 5 eingegeben habe?</p>
</blockquote>
<p>Wein sizeof die Größe in char-Größen angibt.</p>
<blockquote>
<p>Wofür steht eine &quot;8&quot; im &quot;8Junction&quot; als Ausgabe für &quot;typeid ((*Iter)).name()&quot; oder typeid ((* array[ti])).name() ?</p>
</blockquote>
<p>Keine Ahnung, die Ausgabe von typeid ist nicht standardisiert. Vielleicht stehen im Handbuch deines Compilers Details.</p>
<blockquote>
<p>was kann ich noch alles verbessern?</p>
</blockquote>
<p>Vor allem erstmal die Art und Weise wie du Elemente in die Liste einfügst, siehe oben. Der Rest des quelltextes ist mir zu lang um mir alles anzugucken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1838868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838868</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 14 Jan 2010 15:14:43 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 15:35:47 GMT]]></title><description><![CDATA[<p>SeppJ auf jeden Fall danke dir!<br />
&quot;benutz einfach direkt die Einfügeoperationen des Containers. &quot;<br />
gern, wie geht n das nur? <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>
<pre><code class="language-cpp">JunctionList.push_back(Junction(id, x, y));
</code></pre>
<p>so?<br />
wird zwar kompiliert aber die Ausgabe von der Liste ist nicht richtig.<br />
Von dem Array dagegen schon. Kein Plan woran es liegt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f622.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--crying_face"
      title=";-("
      alt="😢"
    /><br />
Ausgabe:</p>
<pre><code>JunctionList.size: 4
8Junction ID 112 X:1.41531e-43 Y:0
8Junction ID 112 X:1.41531e-43 Y:0
8Junction ID 112 X:1.41531e-43 Y:0
8Junction ID 112 X:1.41531e-43 Y:0

sizeof(array): 20
8Junction ID: 317557901 X: 630.25 Y: 1697
8Junction ID: 317558017 X: 644.22 Y: 952
8Junction ID: 317558232 X: 414.62 Y: 0
8Junction ID: 6350306 X: 0 Y: 1124.5
Segmentation fault
</code></pre>
<p>warum wird ein Fehler &quot;Segmentation fault&quot; ausgegeben?</p>
<p>Ausgabe von der Liste</p>
<pre><code class="language-cpp">ostream &amp; operator&lt;&lt;(ostream &amp;output, const Junction &amp; junc) {
    output &lt;&lt; &quot;ID &quot; &lt;&lt; junc.id &lt;&lt; &quot; X:&quot; &lt;&lt; junc.x &lt;&lt; &quot; Y:&quot; &lt;&lt; junc.y &lt;&lt; endl;
    return output;
}
....
cout &lt;&lt; &quot;JunctionList.size: &quot; &lt;&lt; JunctionList.size() &lt;&lt; endl;
    for (Iter = JunctionList.begin(); Iter != JunctionList.end(); ++Iter) cout &lt;&lt; typeid ((*Iter)).name() &lt;&lt; &quot; &quot; &lt;&lt;  *Iter; // print all
    cout &lt;&lt; endl;
</code></pre>
<p>Auf private Elemente greife ich über GET Methode oder frend Funktion zu.<br />
(steht doch da <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/1838887</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838887</guid><dc:creator><![CDATA[sugarray21]]></dc:creator><pubDate>Thu, 14 Jan 2010 15:35:47 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 15:46:18 GMT]]></title><description><![CDATA[<p>sugarray21 schrieb:</p>
<blockquote>
<p>SeppJ auf jeden Fall danke dir!<br />
&quot;benutz einfach direkt die Einfügeoperationen des Containers. &quot;<br />
gern, wie geht n das nur? <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>
<pre><code class="language-cpp">JunctionList.push_back(Junction(id, x, y));
</code></pre>
<p>so?</p>
</blockquote>
<p>Ja.</p>
<blockquote>
<p>wird zwar kompiliert aber die Ausgabe von der Liste ist nicht richtig.<br />
Von dem Array dagegen schon. Kein Plan woran es liegt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f622.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--crying_face"
      title=";-("
      alt="😢"
    /></p>
</blockquote>
<p>Zeig mal den Code wie er jetzt ist.</p>
<blockquote>
<p>warum wird ein Fehler &quot;Segmentation fault&quot; ausgegeben?</p>
</blockquote>
<p>Weil das Array 5 Elemente hat, du aber versuchst, auf 20 zuzugreifen.</p>
<blockquote>
<p>Auf private Elemente greife ich über GET Methode oder frend Funktion zu.<br />
(steht doch da <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>
</blockquote>
<p>Das ist ja auch völlig in Ordnung. Inwiefern klappt das denn bei der Liste nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1838893</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838893</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 14 Jan 2010 15:46:18 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 15:56:59 GMT]]></title><description><![CDATA[<p>main.cpp</p>
<pre><code class="language-cpp">#ifdef HAVE_CONFIG_H
#endif

#include &lt;libxml++-2.6/libxml++/libxml++.h&gt;
#include &lt;libxml++-2.6/libxml++/parsers/textreader.h&gt;

#include &lt;iostream&gt;
#include &lt;list&gt;
#include &lt;typeinfo&gt; // &lt;&lt; typeid(reader.get_value()).name() &lt;&lt;
#include &lt;boost/lexical_cast.hpp&gt;

#include &quot;Junction.h&quot;
using namespace std;

ostream &amp; operator&lt;&lt;(ostream &amp;output, const Junction &amp; junc) {
    output &lt;&lt; &quot;ID &quot; &lt;&lt; junc.id &lt;&lt; &quot; X:&quot; &lt;&lt; junc.x &lt;&lt; &quot; Y:&quot; &lt;&lt; junc.y &lt;&lt; endl;
    return output;
}

int main(int argc, char* argv[]) {

    list &lt;Junction&gt; JunctionList;
    list &lt;Junction&gt;::iterator Iter;

    Junction * array[4];
    int ai = 0;

    try {
        xmlpp::TextReader reader(&quot;/home/sugarray21/sumo-0.11.1/maps/map_very_small.net&quot;);

        while (reader.read()) {
            if (reader.get_name() == &quot;junction&quot;) {
                int id;
                float x, y;
                cout &lt;&lt; &quot;--- junction ---&quot; &lt;&lt; endl;

                if (reader.has_attributes()) {
                    reader.move_to_first_attribute();
                    do {

                        if (reader.get_name() == &quot;id&quot;) {
                            id = boost::lexical_cast&lt;int&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  ID:: &quot; &lt;&lt; id &lt;&lt; endl;
                        } else if (reader.get_name() == &quot;x&quot;) {
                            x = boost::lexical_cast&lt;float&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  X :: &quot; &lt;&lt; x &lt;&lt; endl;
                        } else if (reader.get_name() == &quot;y&quot;) {
                            y = boost::lexical_cast&lt;float&gt;(reader.get_value());
                            cout &lt;&lt; &quot;  Y :: &quot; &lt;&lt; y &lt;&lt; endl;
                        }

                    } while (reader.move_to_next_attribute());

                    cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; id &lt;&lt; &quot;: &quot; &lt;&lt; x &lt;&lt; &quot;: &quot; &lt;&lt; y &lt;&lt; endl;

                    Junction *t_Junction = new Junction(id, x, y);
                    cout &lt;&lt; &quot;Junction: &quot; &lt;&lt; t_Junction-&gt;getID() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction-&gt;getX() &lt;&lt; &quot;: &quot; &lt;&lt; t_Junction-&gt;getY() &lt;&lt; endl;
                    array[ai++] = t_Junction;

                    JunctionList.push_back(Junction(id, x, y));

                    reader.move_to_element();
                } else {
                }

            }

        }
    } catch (const exception&amp; e) {
        cout &lt;&lt; &quot;Exception caught: &quot; &lt;&lt; e.what() &lt;&lt; endl;
    }

    cout &lt;&lt; endl &lt;&lt; &quot;JunctionList.size: &quot; &lt;&lt; JunctionList.size() &lt;&lt; endl;
    for (Iter = JunctionList.begin(); Iter != JunctionList.end(); ++Iter)
        cout &lt;&lt; typeid ((*Iter)).name() &lt;&lt; &quot; &quot; &lt;&lt; *Iter; // print all

    cout &lt;&lt; endl &lt;&lt; &quot;sizeof(array): &quot; &lt;&lt; sizeof (array) / sizeof (array[0]) &lt;&lt; endl;
    for (int ti = 0; ti &lt; sizeof (array) / sizeof (array[0]); ti++) {
        cout &lt;&lt; typeid ((* array[ti])).name() &lt;&lt; &quot; &quot; &lt;&lt; *array[ti];
    }
}
</code></pre>
<p>Ausgabe von der Liste ist Bullshit:</p>
<pre><code>--- junction ---
  ID:: 317557901
  X :: 630.25
  Y :: 1697
Junction: 317557901: 630.25: 1697
Junction: 317557901: 630.25: 1697
--- junction ---
  ID:: 317558017
  X :: 644.22
  Y :: 952
Junction: 317558017: 644.22: 952
Junction: 317558017: 644.22: 952
--- junction ---
  ID:: 317558232
  X :: 414.62
  Y :: 0
Junction: 317558232: 414.62: 0
Junction: 317558232: 414.62: 0
--- junction ---
  ID:: 6350306
  X :: 0
  Y :: 1124.5
Junction: 6350306: 0: 1124.5
Junction: 6350306: 0: 1124.5

JunctionList.size: 4
8Junction ID 112 X:1.41531e-43 Y:0
8Junction ID 112 X:1.41531e-43 Y:0
8Junction ID 112 X:1.41531e-43 Y:0
8Junction ID 112 X:1.41531e-43 Y:0

sizeof(array): 4
8Junction ID 317557901 X:630.25 Y:1697
8Junction ID 317558017 X:644.22 Y:952
8Junction ID 317558232 X:414.62 Y:0
8Junction ID 6350306 X:0 Y:1124.5
Press [Enter] to close the terminal ...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1838903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838903</guid><dc:creator><![CDATA[sugarray21]]></dc:creator><pubDate>Thu, 14 Jan 2010 15:56:59 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 16:15:50 GMT]]></title><description><![CDATA[<p>Die falsche Übergabe an die Liste liegt daran, dass du einen Copykonstruktor definiert hast, dieser aber nichts tut. Deshalb wird, wenn push_back das Objekt in die Liste kopiert, ein uninitialisiertes Objekt erzeugt. Du brauchst für deine Klasse weder einen Copykonstruktor noch einen Destruktor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1838909</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838909</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 14 Jan 2010 16:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 16:24:46 GMT]]></title><description><![CDATA[<p>YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS!</p>
<pre><code>JunctionList.size: 4
8Junction ID 317557901 X:630.25 Y:1697
8Junction ID 317558017 X:644.22 Y:952
8Junction ID 317558232 X:414.62 Y:0
8Junction ID 6350306 X:0 Y:1124.5

sizeof(array): 4
P8Junction ID 317557901 X:630.25 Y:1697
P8Junction ID 317558017 X:644.22 Y:952
P8Junction ID 317558232 X:414.62 Y:0
P8Junction ID 6350306 X:0 Y:1124.5
Press [Enter] to close the terminal ...
</code></pre>
<p>sieht doch schon mal besser aus.<br />
DANKE DIR 1000 MAL !!!<br />
Du hast dir aber echt viel Zeit für mich genommen! Respekt!<br />
Was ich noch nicht verstehe ist,<br />
warum ich gar keinen Konstruktor und einen Destruktor brauche?<br />
Hättest du jetzt gesagt, das ich einen selber definieren soll, hätte ich noch verstanden. Wird einer (Kopierkonstruktor) impliziert erstellt und aufgerufen?<br />
Was ist mir dem Standartkonstruktor und dem Destruktor?<br />
Danke Dir vielmals!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1838913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838913</guid><dc:creator><![CDATA[sugarray21]]></dc:creator><pubDate>Thu, 14 Jan 2010 16:24:46 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 16:29:26 GMT]]></title><description><![CDATA[<p>Ja, wenn man keinen Konstruktor, Destruktor, Kopierkonstruktor oder Zuweisungsoperator definiert und es wird trotzdem einer gebraucht, dann wird vom Compiler automatisch eine triviale Version erstellt. Diese erzeugt/vernchtet/kopiert (je nachdem) einfach stumpf alle Datenelemente. das ist in vielen Fällen völlig ausreichend, so auch hier.</p>
<p>Die wichtigste Ausnahme, wann man diese Funktionen selber schreiben sollte, ist, wenn man in der Klasse Zeiger auf andere Objekte hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1838916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838916</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 14 Jan 2010 16:29:26 GMT</pubDate></item><item><title><![CDATA[Reply to Anfänger: XML Parsen und Objekte in einer Liste speichern klappt nicht ;-( on Thu, 14 Jan 2010 16:48:58 GMT]]></title><description><![CDATA[<p>ah stimmt habe ich doch vor kurzem gelesen, dann muss man den Kopierkonstruktor selber<br />
schreiben und neuen Zeiger auf kopierte Daten erstellen. Danke dir !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1838929</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1838929</guid><dc:creator><![CDATA[sugarray21]]></dc:creator><pubDate>Thu, 14 Jan 2010 16:48:58 GMT</pubDate></item></channel></rss>