<?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[klasseninstanz in vector]]></title><description><![CDATA[<p>hallo,<br />
folgendes problem.</p>
<p>eine instanz der klasse mynode.cpp</p>
<pre><code class="language-cpp">#include &quot;StdAfx.h&quot;
#include &quot;mynode.h&quot;

mynode::mynode(void)
{

}

mynode::mynode(string n, int i){
	name = n;
	index = i;
}

mynode::~mynode(void)
{
}

void mynode::setNode(string n, int i){
	name = n;
	index = i;
}

string mynode::getName(){
	return name;
}

int mynode::getIndex(){
	return index;
}
</code></pre>
<p>soll in einem vector der klasse myapp.cpp gespeichert werden.</p>
<pre><code class="language-cpp">#include &quot;StdAfx.h&quot;
#include &quot;myapp.h&quot;
#include &quot;mynode.h&quot;

myapp::myapp(void)
{

}

myapp::~myapp(void)
{
}
//System::String^ s
void myapp::addNode(std::string s, int i){
	mynode *mn = new mynode(s,i);
	vec_nodes.push_back(*mn);
	delete mn;
	}

std::string myapp::SysToStd(System::String^ S){
    std::string ss; 
    if (S-&gt;Length == 0) return ss;
	System::IntPtr ip = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(S);
    try{
		ss = static_cast&lt;const char*&gt;(ip.ToPointer());
    }__finally{
        System::Runtime::InteropServices::Marshal::FreeHGlobal(ip);
    }
    return ss;
}
</code></pre>
<p>eine instanz von myapp wird wiederum in Form1.h aufgerufen. aus einer xml datei sollen ein string und ein in gelesen werden.</p>
<pre><code>#pragma once

#include &quot;mynode.h&quot;
#include &quot;myedge.h&quot;
#include &quot;myapp.h&quot;

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Xml;

namespace Ue02 {

	/// &lt;summary&gt;
	/// Zusammenfassung für Form1
	///
	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
	///          arbeiten, die diesem Formular zugewiesen sind.
	/// &lt;/summary&gt;
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
		}

	protected:
		/// &lt;summary&gt;
		/// Verwendete Ressourcen bereinigen.
		/// &lt;/summary&gt;
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::ComboBox^  comboBox1;
	protected: 
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::ComboBox^  comboBox2;

	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;

	protected: 

	private:
		/// &lt;summary&gt;
		/// Erforderliche Designervariable.
		/// &lt;/summary&gt;
		System::ComponentModel::Container ^components;
		myapp	*ma;
	private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::Button^  button3;
			 String^ filename;

#pragma region Windows Form Designer generated code
		/// &lt;summary&gt;
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// &lt;/summary&gt;
		void InitializeComponent(void)
		{
			this-&gt;comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this-&gt;label1 = (gcnew System::Windows::Forms::Label());
			this-&gt;label2 = (gcnew System::Windows::Forms::Label());
			this-&gt;comboBox2 = (gcnew System::Windows::Forms::ComboBox());
			this-&gt;button1 = (gcnew System::Windows::Forms::Button());
			this-&gt;button2 = (gcnew System::Windows::Forms::Button());
			this-&gt;openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
			this-&gt;textBox1 = (gcnew System::Windows::Forms::TextBox());
			this-&gt;button3 = (gcnew System::Windows::Forms::Button());
			this-&gt;SuspendLayout();
			// 
			// comboBox1
			// 
			this-&gt;comboBox1-&gt;FormattingEnabled = true;
			this-&gt;comboBox1-&gt;Location = System::Drawing::Point(159, 39);
			this-&gt;comboBox1-&gt;Name = L&quot;comboBox1&quot;;
			this-&gt;comboBox1-&gt;Size = System::Drawing::Size(181, 21);
			this-&gt;comboBox1-&gt;TabIndex = 0;
			// 
			// label1
			// 
			this-&gt;label1-&gt;AutoSize = true;
			this-&gt;label1-&gt;Location = System::Drawing::Point(24, 39);
			this-&gt;label1-&gt;Name = L&quot;label1&quot;;
			this-&gt;label1-&gt;Size = System::Drawing::Size(32, 13);
			this-&gt;label1-&gt;TabIndex = 2;
			this-&gt;label1-&gt;Text = L&quot;Start:&quot;;
			// 
			// label2
			// 
			this-&gt;label2-&gt;AutoSize = true;
			this-&gt;label2-&gt;Location = System::Drawing::Point(27, 91);
			this-&gt;label2-&gt;Name = L&quot;label2&quot;;
			this-&gt;label2-&gt;Size = System::Drawing::Size(63, 13);
			this-&gt;label2-&gt;TabIndex = 3;
			this-&gt;label2-&gt;Text = L&quot;Destination:&quot;;
			// 
			// comboBox2
			// 
			this-&gt;comboBox2-&gt;FormattingEnabled = true;
			this-&gt;comboBox2-&gt;Location = System::Drawing::Point(159, 83);
			this-&gt;comboBox2-&gt;Name = L&quot;comboBox2&quot;;
			this-&gt;comboBox2-&gt;Size = System::Drawing::Size(181, 21);
			this-&gt;comboBox2-&gt;TabIndex = 4;
			// 
			// button1
			// 
			this-&gt;button1-&gt;Location = System::Drawing::Point(27, 262);
			this-&gt;button1-&gt;Name = L&quot;button1&quot;;
			this-&gt;button1-&gt;Size = System::Drawing::Size(101, 23);
			this-&gt;button1-&gt;TabIndex = 6;
			this-&gt;button1-&gt;Text = L&quot;Start&quot;;
			this-&gt;button1-&gt;UseVisualStyleBackColor = true;
			this-&gt;button1-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button1_Click);
			// 
			// button2
			// 
			this-&gt;button2-&gt;Location = System::Drawing::Point(138, 262);
			this-&gt;button2-&gt;Name = L&quot;button2&quot;;
			this-&gt;button2-&gt;Size = System::Drawing::Size(101, 23);
			this-&gt;button2-&gt;TabIndex = 7;
			this-&gt;button2-&gt;Text = L&quot;Nodes laden&quot;;
			this-&gt;button2-&gt;UseVisualStyleBackColor = true;
			this-&gt;button2-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button2_Click);
			// 
			// openFileDialog1
			// 
			this-&gt;openFileDialog1-&gt;FileName = L&quot;openFileDialog1&quot;;
			// 
			// textBox1
			// 
			this-&gt;textBox1-&gt;AcceptsReturn = true;
			this-&gt;textBox1-&gt;AcceptsTab = true;
			this-&gt;textBox1-&gt;Location = System::Drawing::Point(27, 125);
			this-&gt;textBox1-&gt;Multiline = true;
			this-&gt;textBox1-&gt;Name = L&quot;textBox1&quot;;
			this-&gt;textBox1-&gt;ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this-&gt;textBox1-&gt;Size = System::Drawing::Size(313, 119);
			this-&gt;textBox1-&gt;TabIndex = 8;
			this-&gt;textBox1-&gt;TextChanged += gcnew System::EventHandler(this, &amp;Form1::textBox1_TextChanged);
			// 
			// button3
			// 
			this-&gt;button3-&gt;Location = System::Drawing::Point(251, 262);
			this-&gt;button3-&gt;Name = L&quot;button3&quot;;
			this-&gt;button3-&gt;Size = System::Drawing::Size(88, 23);
			this-&gt;button3-&gt;TabIndex = 9;
			this-&gt;button3-&gt;Text = L&quot;Edges laden&quot;;
			this-&gt;button3-&gt;UseVisualStyleBackColor = true;
			this-&gt;button3-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button3_Click);
			// 
			// Form1
			// 
			this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this-&gt;ClientSize = System::Drawing::Size(365, 301);
			this-&gt;Controls-&gt;Add(this-&gt;button3);
			this-&gt;Controls-&gt;Add(this-&gt;textBox1);
			this-&gt;Controls-&gt;Add(this-&gt;button2);
			this-&gt;Controls-&gt;Add(this-&gt;button1);
			this-&gt;Controls-&gt;Add(this-&gt;comboBox2);
			this-&gt;Controls-&gt;Add(this-&gt;label2);
			this-&gt;Controls-&gt;Add(this-&gt;label1);
			this-&gt;Controls-&gt;Add(this-&gt;comboBox1);
			this-&gt;Name = L&quot;Form1&quot;;
			this-&gt;Text = L&quot;Form1&quot;;
			this-&gt;ResumeLayout(false);
			this-&gt;PerformLayout();

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {

			  // OpenFile-Dialog mit Filter 
				 // Der Pfad wird in String ^filename gespeichert
				 openFileDialog1-&gt;Filter = &quot;Xml-Datei (*.xml)|*.xml|Alle Dateien (*.*)|*.*&quot;;
				 openFileDialog1-&gt;Title = &quot;Eine *.xml-Datei&quot;;
				 openFileDialog1-&gt;FileName = &quot;Nodes.xml&quot;;

				 if(openFileDialog1-&gt;ShowDialog() ==System::Windows::Forms::DialogResult::OK){

					 filename = openFileDialog1-&gt;FileName-&gt;ToString();
				 }

			XmlTextReader^ reader = nullptr;
			try{
				// Lädt den reader mit Datei und ignoriert Whitespaces
				reader = gcnew XmlTextReader(filename);
				reader-&gt;WhitespaceHandling = WhitespaceHandling::None;

				if(!reader-&gt;IsStartElement(&quot;nodes&quot;)){
					MessageBox::Show(&quot;Keine Xml Datei mit Nodes ausgewählt!&quot;);
					return;}

				while (reader-&gt;Read())
				{

					switch (reader-&gt;NodeType)
					{

					case XmlNodeType::Element:

						String ^s;
						int index;
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						//textBox1-&gt;AppendText(reader-&gt;Name + &quot;\r\n&quot;);
						if (reader-&gt;Name == &quot;index&quot;) index = Convert::ToInt32(reader-&gt;ReadElementString());
						if (reader-&gt;Name == &quot;name&quot;) s = reader-&gt;ReadElementString();

						ma-&gt;addNode(&quot;test&quot;, index);

						break;
					case XmlNodeType::Text:
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						//textBox1-&gt;AppendText(reader-&gt;Value + &quot;\r\n&quot;);

						break;
					}
				}
			}catch(Exception ^e){ 
				MessageBox::Show(&quot;Keine Datei ausgewählt&quot;);
				MessageBox::Show(e-&gt;ToString());
			}

			finally
			{
				if (reader != nullptr)	// Wenn reader instantiert wurde, dann schließe reader
					reader-&gt;Close();

			}

		 }
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			  // OpenFile-Dialog mit Filter 
				 // Der Pfad wird in String ^filename gespeichert
				 openFileDialog1-&gt;Filter = &quot;Xml-Datei (*.xml)|*.xml|Alle Dateien (*.*)|*.*&quot;;
				 openFileDialog1-&gt;Title = &quot;Eine *.xml-Datei&quot;;
				 openFileDialog1-&gt;FileName = &quot;Edges.xml&quot;;

				 if(openFileDialog1-&gt;ShowDialog() ==System::Windows::Forms::DialogResult::OK){

					 filename = openFileDialog1-&gt;FileName-&gt;ToString();
				 }

			XmlTextReader^ reader = nullptr;
			try{
				// Lädt den reader mit Datei und ignoriert Whitespaces
				reader = gcnew XmlTextReader(filename);
				reader-&gt;WhitespaceHandling = WhitespaceHandling::None;

				if(!reader-&gt;IsStartElement(&quot;edges&quot;)){
					MessageBox::Show(&quot;Keine Xml Datei mit Edges ausgewählt!&quot;);
					return;}

				while (reader-&gt;Read())
				{

					switch (reader-&gt;NodeType)
					{

					case XmlNodeType::Element:
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						textBox1-&gt;AppendText(reader-&gt;Name + &quot;\r\n&quot;);
						break;
					case XmlNodeType::Text:
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						textBox1-&gt;AppendText(reader-&gt;Value + &quot;\r\n&quot;);
						break;
					}
				}
			}catch(Exception ^e){ 
				MessageBox::Show(&quot;Keine Datei ausgewählt&quot;);
				MessageBox::Show(e-&gt;ToString());
			}

			finally
			{
				if (reader != nullptr)	// Wenn reader instantiert wurde, dann schließe reader
					reader-&gt;Close();

			}
		 }
};
}
</code></pre>
<p>leider bekomme ich jetzt immer einer exception. Nullreferenceexception. &quot;Ein Objektverweis wurde nicht auf eine Objektinstanz festegelegt&quot; Ich verstehe nicht ganz wieso.</p>
<p>vielen dank für die hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/255510/klasseninstanz-in-vector</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 23:42:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/255510.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Dec 2009 17:34:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:34:47 GMT]]></title><description><![CDATA[<p>hallo,<br />
folgendes problem.</p>
<p>eine instanz der klasse mynode.cpp</p>
<pre><code class="language-cpp">#include &quot;StdAfx.h&quot;
#include &quot;mynode.h&quot;

mynode::mynode(void)
{

}

mynode::mynode(string n, int i){
	name = n;
	index = i;
}

mynode::~mynode(void)
{
}

void mynode::setNode(string n, int i){
	name = n;
	index = i;
}

string mynode::getName(){
	return name;
}

int mynode::getIndex(){
	return index;
}
</code></pre>
<p>soll in einem vector der klasse myapp.cpp gespeichert werden.</p>
<pre><code class="language-cpp">#include &quot;StdAfx.h&quot;
#include &quot;myapp.h&quot;
#include &quot;mynode.h&quot;

myapp::myapp(void)
{

}

myapp::~myapp(void)
{
}
//System::String^ s
void myapp::addNode(std::string s, int i){
	mynode *mn = new mynode(s,i);
	vec_nodes.push_back(*mn);
	delete mn;
	}

std::string myapp::SysToStd(System::String^ S){
    std::string ss; 
    if (S-&gt;Length == 0) return ss;
	System::IntPtr ip = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(S);
    try{
		ss = static_cast&lt;const char*&gt;(ip.ToPointer());
    }__finally{
        System::Runtime::InteropServices::Marshal::FreeHGlobal(ip);
    }
    return ss;
}
</code></pre>
<p>eine instanz von myapp wird wiederum in Form1.h aufgerufen. aus einer xml datei sollen ein string und ein in gelesen werden.</p>
<pre><code>#pragma once

#include &quot;mynode.h&quot;
#include &quot;myedge.h&quot;
#include &quot;myapp.h&quot;

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Xml;

namespace Ue02 {

	/// &lt;summary&gt;
	/// Zusammenfassung für Form1
	///
	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
	///          arbeiten, die diesem Formular zugewiesen sind.
	/// &lt;/summary&gt;
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Konstruktorcode hier hinzufügen.
			//
		}

	protected:
		/// &lt;summary&gt;
		/// Verwendete Ressourcen bereinigen.
		/// &lt;/summary&gt;
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::ComboBox^  comboBox1;
	protected: 
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::ComboBox^  comboBox2;

	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;

	protected: 

	private:
		/// &lt;summary&gt;
		/// Erforderliche Designervariable.
		/// &lt;/summary&gt;
		System::ComponentModel::Container ^components;
		myapp	*ma;
	private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::Button^  button3;
			 String^ filename;

#pragma region Windows Form Designer generated code
		/// &lt;summary&gt;
		/// Erforderliche Methode für die Designerunterstützung.
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
		/// &lt;/summary&gt;
		void InitializeComponent(void)
		{
			this-&gt;comboBox1 = (gcnew System::Windows::Forms::ComboBox());
			this-&gt;label1 = (gcnew System::Windows::Forms::Label());
			this-&gt;label2 = (gcnew System::Windows::Forms::Label());
			this-&gt;comboBox2 = (gcnew System::Windows::Forms::ComboBox());
			this-&gt;button1 = (gcnew System::Windows::Forms::Button());
			this-&gt;button2 = (gcnew System::Windows::Forms::Button());
			this-&gt;openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
			this-&gt;textBox1 = (gcnew System::Windows::Forms::TextBox());
			this-&gt;button3 = (gcnew System::Windows::Forms::Button());
			this-&gt;SuspendLayout();
			// 
			// comboBox1
			// 
			this-&gt;comboBox1-&gt;FormattingEnabled = true;
			this-&gt;comboBox1-&gt;Location = System::Drawing::Point(159, 39);
			this-&gt;comboBox1-&gt;Name = L&quot;comboBox1&quot;;
			this-&gt;comboBox1-&gt;Size = System::Drawing::Size(181, 21);
			this-&gt;comboBox1-&gt;TabIndex = 0;
			// 
			// label1
			// 
			this-&gt;label1-&gt;AutoSize = true;
			this-&gt;label1-&gt;Location = System::Drawing::Point(24, 39);
			this-&gt;label1-&gt;Name = L&quot;label1&quot;;
			this-&gt;label1-&gt;Size = System::Drawing::Size(32, 13);
			this-&gt;label1-&gt;TabIndex = 2;
			this-&gt;label1-&gt;Text = L&quot;Start:&quot;;
			// 
			// label2
			// 
			this-&gt;label2-&gt;AutoSize = true;
			this-&gt;label2-&gt;Location = System::Drawing::Point(27, 91);
			this-&gt;label2-&gt;Name = L&quot;label2&quot;;
			this-&gt;label2-&gt;Size = System::Drawing::Size(63, 13);
			this-&gt;label2-&gt;TabIndex = 3;
			this-&gt;label2-&gt;Text = L&quot;Destination:&quot;;
			// 
			// comboBox2
			// 
			this-&gt;comboBox2-&gt;FormattingEnabled = true;
			this-&gt;comboBox2-&gt;Location = System::Drawing::Point(159, 83);
			this-&gt;comboBox2-&gt;Name = L&quot;comboBox2&quot;;
			this-&gt;comboBox2-&gt;Size = System::Drawing::Size(181, 21);
			this-&gt;comboBox2-&gt;TabIndex = 4;
			// 
			// button1
			// 
			this-&gt;button1-&gt;Location = System::Drawing::Point(27, 262);
			this-&gt;button1-&gt;Name = L&quot;button1&quot;;
			this-&gt;button1-&gt;Size = System::Drawing::Size(101, 23);
			this-&gt;button1-&gt;TabIndex = 6;
			this-&gt;button1-&gt;Text = L&quot;Start&quot;;
			this-&gt;button1-&gt;UseVisualStyleBackColor = true;
			this-&gt;button1-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button1_Click);
			// 
			// button2
			// 
			this-&gt;button2-&gt;Location = System::Drawing::Point(138, 262);
			this-&gt;button2-&gt;Name = L&quot;button2&quot;;
			this-&gt;button2-&gt;Size = System::Drawing::Size(101, 23);
			this-&gt;button2-&gt;TabIndex = 7;
			this-&gt;button2-&gt;Text = L&quot;Nodes laden&quot;;
			this-&gt;button2-&gt;UseVisualStyleBackColor = true;
			this-&gt;button2-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button2_Click);
			// 
			// openFileDialog1
			// 
			this-&gt;openFileDialog1-&gt;FileName = L&quot;openFileDialog1&quot;;
			// 
			// textBox1
			// 
			this-&gt;textBox1-&gt;AcceptsReturn = true;
			this-&gt;textBox1-&gt;AcceptsTab = true;
			this-&gt;textBox1-&gt;Location = System::Drawing::Point(27, 125);
			this-&gt;textBox1-&gt;Multiline = true;
			this-&gt;textBox1-&gt;Name = L&quot;textBox1&quot;;
			this-&gt;textBox1-&gt;ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this-&gt;textBox1-&gt;Size = System::Drawing::Size(313, 119);
			this-&gt;textBox1-&gt;TabIndex = 8;
			this-&gt;textBox1-&gt;TextChanged += gcnew System::EventHandler(this, &amp;Form1::textBox1_TextChanged);
			// 
			// button3
			// 
			this-&gt;button3-&gt;Location = System::Drawing::Point(251, 262);
			this-&gt;button3-&gt;Name = L&quot;button3&quot;;
			this-&gt;button3-&gt;Size = System::Drawing::Size(88, 23);
			this-&gt;button3-&gt;TabIndex = 9;
			this-&gt;button3-&gt;Text = L&quot;Edges laden&quot;;
			this-&gt;button3-&gt;UseVisualStyleBackColor = true;
			this-&gt;button3-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button3_Click);
			// 
			// Form1
			// 
			this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this-&gt;ClientSize = System::Drawing::Size(365, 301);
			this-&gt;Controls-&gt;Add(this-&gt;button3);
			this-&gt;Controls-&gt;Add(this-&gt;textBox1);
			this-&gt;Controls-&gt;Add(this-&gt;button2);
			this-&gt;Controls-&gt;Add(this-&gt;button1);
			this-&gt;Controls-&gt;Add(this-&gt;comboBox2);
			this-&gt;Controls-&gt;Add(this-&gt;label2);
			this-&gt;Controls-&gt;Add(this-&gt;label1);
			this-&gt;Controls-&gt;Add(this-&gt;comboBox1);
			this-&gt;Name = L&quot;Form1&quot;;
			this-&gt;Text = L&quot;Form1&quot;;
			this-&gt;ResumeLayout(false);
			this-&gt;PerformLayout();

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {

			  // OpenFile-Dialog mit Filter 
				 // Der Pfad wird in String ^filename gespeichert
				 openFileDialog1-&gt;Filter = &quot;Xml-Datei (*.xml)|*.xml|Alle Dateien (*.*)|*.*&quot;;
				 openFileDialog1-&gt;Title = &quot;Eine *.xml-Datei&quot;;
				 openFileDialog1-&gt;FileName = &quot;Nodes.xml&quot;;

				 if(openFileDialog1-&gt;ShowDialog() ==System::Windows::Forms::DialogResult::OK){

					 filename = openFileDialog1-&gt;FileName-&gt;ToString();
				 }

			XmlTextReader^ reader = nullptr;
			try{
				// Lädt den reader mit Datei und ignoriert Whitespaces
				reader = gcnew XmlTextReader(filename);
				reader-&gt;WhitespaceHandling = WhitespaceHandling::None;

				if(!reader-&gt;IsStartElement(&quot;nodes&quot;)){
					MessageBox::Show(&quot;Keine Xml Datei mit Nodes ausgewählt!&quot;);
					return;}

				while (reader-&gt;Read())
				{

					switch (reader-&gt;NodeType)
					{

					case XmlNodeType::Element:

						String ^s;
						int index;
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						//textBox1-&gt;AppendText(reader-&gt;Name + &quot;\r\n&quot;);
						if (reader-&gt;Name == &quot;index&quot;) index = Convert::ToInt32(reader-&gt;ReadElementString());
						if (reader-&gt;Name == &quot;name&quot;) s = reader-&gt;ReadElementString();

						ma-&gt;addNode(&quot;test&quot;, index);

						break;
					case XmlNodeType::Text:
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						//textBox1-&gt;AppendText(reader-&gt;Value + &quot;\r\n&quot;);

						break;
					}
				}
			}catch(Exception ^e){ 
				MessageBox::Show(&quot;Keine Datei ausgewählt&quot;);
				MessageBox::Show(e-&gt;ToString());
			}

			finally
			{
				if (reader != nullptr)	// Wenn reader instantiert wurde, dann schließe reader
					reader-&gt;Close();

			}

		 }
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
		 }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
			  // OpenFile-Dialog mit Filter 
				 // Der Pfad wird in String ^filename gespeichert
				 openFileDialog1-&gt;Filter = &quot;Xml-Datei (*.xml)|*.xml|Alle Dateien (*.*)|*.*&quot;;
				 openFileDialog1-&gt;Title = &quot;Eine *.xml-Datei&quot;;
				 openFileDialog1-&gt;FileName = &quot;Edges.xml&quot;;

				 if(openFileDialog1-&gt;ShowDialog() ==System::Windows::Forms::DialogResult::OK){

					 filename = openFileDialog1-&gt;FileName-&gt;ToString();
				 }

			XmlTextReader^ reader = nullptr;
			try{
				// Lädt den reader mit Datei und ignoriert Whitespaces
				reader = gcnew XmlTextReader(filename);
				reader-&gt;WhitespaceHandling = WhitespaceHandling::None;

				if(!reader-&gt;IsStartElement(&quot;edges&quot;)){
					MessageBox::Show(&quot;Keine Xml Datei mit Edges ausgewählt!&quot;);
					return;}

				while (reader-&gt;Read())
				{

					switch (reader-&gt;NodeType)
					{

					case XmlNodeType::Element:
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						textBox1-&gt;AppendText(reader-&gt;Name + &quot;\r\n&quot;);
						break;
					case XmlNodeType::Text:
						// Wert innerhalb der Tags wird in einen Vektor geschrieben
						textBox1-&gt;AppendText(reader-&gt;Value + &quot;\r\n&quot;);
						break;
					}
				}
			}catch(Exception ^e){ 
				MessageBox::Show(&quot;Keine Datei ausgewählt&quot;);
				MessageBox::Show(e-&gt;ToString());
			}

			finally
			{
				if (reader != nullptr)	// Wenn reader instantiert wurde, dann schließe reader
					reader-&gt;Close();

			}
		 }
};
}
</code></pre>
<p>leider bekomme ich jetzt immer einer exception. Nullreferenceexception. &quot;Ein Objektverweis wurde nicht auf eine Objektinstanz festegelegt&quot; Ich verstehe nicht ganz wieso.</p>
<p>vielen dank für die hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816055</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816055</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:34:47 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:41:31 GMT]]></title><description><![CDATA[<p>das ist die exception:</p>
<blockquote>
<p>System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.<br />
bei std.vector&lt;mynode,std::allocator&lt;mynode&gt; &gt;.size(vector&lt;mynode\,std::allocator&lt;mynode&gt; &gt;* ) in c:\program files\microsoft visual studio 9.0\vc\include\vector:Zeile 726.<br />
bei std.vector&lt;mynode,std::allocator&lt;mynode&gt; &gt;.push_back(vector&lt;mynode\,std::allocator&lt;mynode&gt; &gt;* , mynode* _Val) in c:\program files\microsoft visual studio 9.0\vc\include\vector:Zeile 810.<br />
bei myapp.addNode(myapp* , basic_string&lt;char\,std::char_traits&lt;char&gt;\,std::allocator&lt;char&gt; &gt;* s, Int32 i) in c:\alg-projekte\ue02\ue02\myapp.cpp:Zeile 16.<br />
bei Ue02.Form1.button2_Click(Object sender, EventArgs e) in c:\alg-projekte\ue02\ue02\form1.h:Zeile 230.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1816059</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816059</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:41:31 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:42:26 GMT]]></title><description><![CDATA[<p>WO tritt die Exception denn auf ?</p>
<p>Schau mal mit dem Debugger nach.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816060</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816060</guid><dc:creator><![CDATA[DarkShadow44]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:42:26 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:44:32 GMT]]></title><description><![CDATA[<p>dann wenn er es in den vector schreiben will.<br />
meiner meinung nach ist aber alles korrekt instantiiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816063</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:44:32 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:46:57 GMT]]></title><description><![CDATA[<p>auch das<br />
myapp *ma;<br />
?<br />
Sehe nicht worauf das zeigt. Oder überseh ich das in dem Codehaufen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816064</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:46:57 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:47:19 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">vec_nodes.push_back(*mn);
</code></pre>
<p>hier?</p>
<p>Wie erstellst du denn &quot;vec_nodes&quot; ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816065</guid><dc:creator><![CDATA[DarkShadow44]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:47:19 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:49:08 GMT]]></title><description><![CDATA[<p>hier ist die myapp.h<br />
meiner meinung nach auch korrekt.</p>
<pre><code class="language-cpp">#pragma once
#include &lt;vector&gt;
#include &quot;mynode.h&quot;
#include &quot;myedge.h&quot;

using namespace std;

class myapp
{
private:
	vector &lt;mynode&gt; vec_nodes;
	vector &lt;myedge&gt; vec_edges;

public:
	myapp(void);
	~myapp(void);
	void addNode(std::string s, int i);
	std::string myapp::SysToStd(System::String^ S);

};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1816068</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816068</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:49:08 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:49:32 GMT]]></title><description><![CDATA[<p>Das ist kein C++, ist also hier das falsche Forum.<br />
Sieht aber der Fehlermeldung nach zu urteilen schwer danach aus, als wäre ma nicht initialisiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816069</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:49:32 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:50:05 GMT]]></title><description><![CDATA[<p>ich meine worauf zeit ma ?<br />
wer erzeugt wo ein myapp?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816070</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816070</guid><dc:creator><![CDATA[brotbernd]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:50:05 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:50:12 GMT]]></title><description><![CDATA[<pre><code>vec_nodes.push_back(*mn);
</code></pre>
<p>ja, genau an dieser stelle wird die exception geschmissen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816071</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816071</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:50:12 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:53:07 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">myapp *ma;
</code></pre>
<p>zeile 65 in Form1.h. ma ist eine instanz von myapp.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816072</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816072</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:53:07 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:54:02 GMT]]></title><description><![CDATA[<p>Wenn du das ganze Projekt als zip hättest wäre das einfacher...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816073</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816073</guid><dc:creator><![CDATA[DarkShadow44]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:54:02 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:55:25 GMT]]></title><description><![CDATA[<p>glasauge schrieb:</p>
<blockquote>
<p>zeile 65 in Form1.h. ma ist eine instanz von myapp.</p>
</blockquote>
<p>Nö, ma ist ein Zeiger auf myapp.<br />
Es sei denn, * hat in dieser Sprache eine völlig andere Bedeutung als in C++.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816075</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816075</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:55:25 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 17:58:55 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">ma=new myapp();

ma-&gt;addNode(&quot;test&quot;, index);
</code></pre>
<p>gehts damit ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816076</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816076</guid><dc:creator><![CDATA[DarkShadow44]]></dc:creator><pubDate>Tue, 01 Dec 2009 17:58:55 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 18:26:13 GMT]]></title><description><![CDATA[<p>ja, damit funktioniert es. jetzt bekomme ich aber eine exception bei SysToStd bzw StdToSys.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816092</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 18:26:13 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 18:31:34 GMT]]></title><description><![CDATA[<p>wo könnte man denn &quot;ma = new myapp()&quot; aufrufen, damit es bei formularaufruf instantiiert wird und nicht erst bei klick auf den button.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816095</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 18:31:34 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 18:34:39 GMT]]></title><description><![CDATA[<p>glasauge schrieb:</p>
<blockquote>
<p>wo könnte man denn &quot;ma = new myapp()&quot; aufrufen, damit es bei formularaufruf instantiiert wird und nicht erst bei klick auf den button.</p>
</blockquote>
<p>Im Konstruktor?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816099</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Tue, 01 Dec 2009 18:34:39 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 18:40:50 GMT]]></title><description><![CDATA[<p>ok, ich hab es jetzt im konstrukto von Form1.h stehen.</p>
<p>Jetzt wirft er mir diese Exception:</p>
<pre><code>System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei myapp.SysToStd(myapp* , basic_string&lt;char\,std::char_traits&lt;char&gt;\,std::allocator&lt;char&gt; &gt;* , String S) in c:\alg-projekte\ue02\ue02\myapp.cpp:Zeile 19.
   bei myapp.addNode(myapp* , String s, Int32 i) in c:\alg-projekte\ue02\ue02\myapp.cpp:Zeile 34.
   bei Ue02.Form1.button2_Click(Object sender, EventArgs e) in c:\alg-projekte\ue02\ue02\form1.h:Zeile 232.
</code></pre>
<p>also im grunde genommen, der gleiche fehler.</p>
<p>hier nochmal die veränderte myapp.cpp</p>
<pre><code>#include &quot;StdAfx.h&quot;
#include &quot;myapp.h&quot;
#include &quot;mynode.h&quot;

myapp::myapp(void)
{

}

myapp::~myapp(void)
{
}
//System::String^ s

std::string myapp::SysToStd(System::String^ S){
    std::string ss; 
    if (S-&gt;Length == 0) return ss;
	System::IntPtr ip = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(S);
    try{
		ss = static_cast&lt;const char*&gt;(ip.ToPointer());
    }__finally{
        System::Runtime::InteropServices::Marshal::FreeHGlobal(ip);
    }
    return ss;
}

System::String^ myapp::StdToSys(string str){
	return gcnew System::String(str.c_str());
}

void myapp::addNode(System::String^ s, int i){
	mynode *mn = new mynode(SysToStd(s),i);
	vec_nodes.push_back(*mn);
	delete mn;
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1816109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816109</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 18:40:50 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 21:43:32 GMT]]></title><description><![CDATA[<p>hat niemand eine idee, woran es liegen könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816206</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816206</guid><dc:creator><![CDATA[glasauge]]></dc:creator><pubDate>Tue, 01 Dec 2009 21:43:32 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 22:03:26 GMT]]></title><description><![CDATA[<p><em>System.NullReferenceException</em> frag doch mal asm-forum nach... oder du probierst einfach alle foren durch, bis du das richtige gefunden hast...<br />
oder du weist, was du dort machst und postest in nem .NET Unterforum... hört sich fast vernünftig an, oder?</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816209</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 01 Dec 2009 22:03:26 GMT</pubDate></item><item><title><![CDATA[Reply to klasseninstanz in vector on Tue, 01 Dec 2009 22:36:39 GMT]]></title><description><![CDATA[<p>glasauge schrieb:</p>
<blockquote>
<p>ok, ich hab es jetzt im konstrukto von Form1.h stehen.</p>
</blockquote>
<p>Wie wäre es wenn du dich mal mit dem C++/CLI Forum beschäftigst? Sofern (was mangels Headern nicht sichtbar ist) mynode als .Net Klasse deklariert wurde, musst du diese auch mit gcnew (und dem ^ statt <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="😉"
    /> verwenden. Meine C++/CLI-Kenntnisse sind aber nur maginal.</p>
<p>Und C++/CLI gehört definitiv nicht in das C++ Forum, da es zwei verschiedene Sprachen sind, wobei erstere eine weitgehende Kompatibilität zu C++ hat, nicht aber umgekehrt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1816228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1816228</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Tue, 01 Dec 2009 22:36:39 GMT</pubDate></item></channel></rss>