<?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[Class object dynamic Pointer]]></title><description><![CDATA[<p>I have been working on the follwoing code.<br />
A class named Vektor contains a dynamic pointer . I do not know if the constructor and destructor is called on automatically? if not when and how to call them. Can any explain about it please?</p>
<pre><code class="language-cpp">//vector_Dyn.h
// vector_Dyn.cpp
#include&lt;iostream&gt;
#include&lt;cmath&gt;
#include&lt;cstdlib&gt;

#ifndef _vector_Dyn_h__
#define _vector_Dyn_h__
class Vektor{
private:
	int itsLength;
	float *itsElement;
public: 
	Vektor(); /*standard-konstruktor */
	Vektor(int n); /* Konstruktor zur Erzeugung eines 
	n dimensional vectors*/

	~Vektor(); // Destkruktor 
	void Read(); // liest über Tastatur elemente ein 
	// und weist sie itsElents zu

	void Write();
	// gibt untereinander die Elemente auf den Bildschrim aus.

	float Betrag();
	// berechnet den Betrag des Vecktors und  gibt in zurück.	

};
#endif
using namespace std;

int main (){
	int length; 
	Vektor *vektor = NULL;
	cout &lt;&lt; &quot;Vektor-Rechnung&quot; &lt;&lt; endl;
	int abbruch = 0;

	do
	{
	//Erzeugen
	cout &lt;&lt; &quot;Wieviele Elemente? --&gt;&quot;;
	cin &gt;&gt; length;
	cout &lt;&lt; endl;
	vektor = new Vektor(length);
	//Verarbeiten
	cout &lt;&lt; &quot;Bitte die &quot; &lt;&lt; length &lt;&lt; &quot; Elemente eingeben.&quot; &lt;&lt; endl;
	(*vektor).Read();
	cout &lt;&lt; &quot;Es wurde eingelesen:&quot; &lt;&lt; endl;
	(*vektor).Write();
	cout &lt;&lt; &quot;Und sein Betrag ist &quot; &lt;&lt; (*vektor).Betrag() &lt;&lt; endl;
	//Freigeben
	delete vektor;
	vektor = NULL;

	cout &lt;&lt; &quot;Noch einen Durchlauf (1/0) --&gt;&quot;;
	cin &gt;&gt; abbruch;
	cout &lt;&lt; endl;
	}
	while (abbruch != 1);

return 0;}

// Defining the vector class members:

Vektor::Vektor(){
//standart konstruktor
cout &lt;&lt; &quot;Standardkonstruktor aufgerufen &quot;&lt;&lt;endl;
itsLength=0;
itsElement=NULL;
}
Vektor::Vektor(int n){
//Konstruktor zu Erzeugng einese  n-dimensionalen vektors.
	cout &lt;&lt; &quot;Konstruktor mit vorgegebene Lange aufgerufen.&quot; &lt;&lt;endl;
	if(n&gt;0){
	itsLength=n;
	itsElement= new float[n];
	}
	else{
		cout &lt;&lt; &quot;Mit Lange &quot;&lt;&lt;n&lt;&lt; &quot; kann keine Vektor erzeugt werden. 	\n&quot;;
		cout &lt;&lt;endl;
		exit(1);
	}
}
// Vektor Destruktor
Vektor::~Vektor(){
	itsLength=0; //eigentlich nicht notig aber damit er etwas zu tun bekommt
	delete[] itsElement;	
	// das ist notwendig freigabe des Speichers
	itsElement=NULL;
}
void Vektor::Read(){
	int i;
	cout &lt;&lt;endl;
	for (i=0; i&lt;itsLength; i++){
		cout &lt;&lt; &quot;vektor[&quot;&lt;&lt;i&lt;&lt;&quot;]: --&gt;&quot;;
		cin&gt;&gt;*(itsElement+i);
		cout &lt;&lt;endl;

	}
}	

	void Vektor::Write(){
		for (int i=0; i&lt;itsLength; i++){
			cout &lt;&lt; &quot;vektor [&quot;&lt;&lt;i&lt;&lt;&quot;]=\t &quot;&lt;&lt; *(itsElement+i)&lt;&lt;endl;

		}
	}
	float Vektor::Betrag(){
		float ergebnis=0.0;
		for(int i=0; i&lt;itsLength;i++){
			ergebnis=ergebnis+(*(itsElement+i)*(*(itsElement+i)));
		}
		return sqrt(ergebnis);
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/295506/class-object-dynamic-pointer</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 10:28:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/295506.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Nov 2011 17:12:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Class object dynamic Pointer on Tue, 15 Nov 2011 17:12:25 GMT]]></title><description><![CDATA[<p>I have been working on the follwoing code.<br />
A class named Vektor contains a dynamic pointer . I do not know if the constructor and destructor is called on automatically? if not when and how to call them. Can any explain about it please?</p>
<pre><code class="language-cpp">//vector_Dyn.h
// vector_Dyn.cpp
#include&lt;iostream&gt;
#include&lt;cmath&gt;
#include&lt;cstdlib&gt;

#ifndef _vector_Dyn_h__
#define _vector_Dyn_h__
class Vektor{
private:
	int itsLength;
	float *itsElement;
public: 
	Vektor(); /*standard-konstruktor */
	Vektor(int n); /* Konstruktor zur Erzeugung eines 
	n dimensional vectors*/

	~Vektor(); // Destkruktor 
	void Read(); // liest über Tastatur elemente ein 
	// und weist sie itsElents zu

	void Write();
	// gibt untereinander die Elemente auf den Bildschrim aus.

	float Betrag();
	// berechnet den Betrag des Vecktors und  gibt in zurück.	

};
#endif
using namespace std;

int main (){
	int length; 
	Vektor *vektor = NULL;
	cout &lt;&lt; &quot;Vektor-Rechnung&quot; &lt;&lt; endl;
	int abbruch = 0;

	do
	{
	//Erzeugen
	cout &lt;&lt; &quot;Wieviele Elemente? --&gt;&quot;;
	cin &gt;&gt; length;
	cout &lt;&lt; endl;
	vektor = new Vektor(length);
	//Verarbeiten
	cout &lt;&lt; &quot;Bitte die &quot; &lt;&lt; length &lt;&lt; &quot; Elemente eingeben.&quot; &lt;&lt; endl;
	(*vektor).Read();
	cout &lt;&lt; &quot;Es wurde eingelesen:&quot; &lt;&lt; endl;
	(*vektor).Write();
	cout &lt;&lt; &quot;Und sein Betrag ist &quot; &lt;&lt; (*vektor).Betrag() &lt;&lt; endl;
	//Freigeben
	delete vektor;
	vektor = NULL;

	cout &lt;&lt; &quot;Noch einen Durchlauf (1/0) --&gt;&quot;;
	cin &gt;&gt; abbruch;
	cout &lt;&lt; endl;
	}
	while (abbruch != 1);

return 0;}

// Defining the vector class members:

Vektor::Vektor(){
//standart konstruktor
cout &lt;&lt; &quot;Standardkonstruktor aufgerufen &quot;&lt;&lt;endl;
itsLength=0;
itsElement=NULL;
}
Vektor::Vektor(int n){
//Konstruktor zu Erzeugng einese  n-dimensionalen vektors.
	cout &lt;&lt; &quot;Konstruktor mit vorgegebene Lange aufgerufen.&quot; &lt;&lt;endl;
	if(n&gt;0){
	itsLength=n;
	itsElement= new float[n];
	}
	else{
		cout &lt;&lt; &quot;Mit Lange &quot;&lt;&lt;n&lt;&lt; &quot; kann keine Vektor erzeugt werden. 	\n&quot;;
		cout &lt;&lt;endl;
		exit(1);
	}
}
// Vektor Destruktor
Vektor::~Vektor(){
	itsLength=0; //eigentlich nicht notig aber damit er etwas zu tun bekommt
	delete[] itsElement;	
	// das ist notwendig freigabe des Speichers
	itsElement=NULL;
}
void Vektor::Read(){
	int i;
	cout &lt;&lt;endl;
	for (i=0; i&lt;itsLength; i++){
		cout &lt;&lt; &quot;vektor[&quot;&lt;&lt;i&lt;&lt;&quot;]: --&gt;&quot;;
		cin&gt;&gt;*(itsElement+i);
		cout &lt;&lt;endl;

	}
}	

	void Vektor::Write(){
		for (int i=0; i&lt;itsLength; i++){
			cout &lt;&lt; &quot;vektor [&quot;&lt;&lt;i&lt;&lt;&quot;]=\t &quot;&lt;&lt; *(itsElement+i)&lt;&lt;endl;

		}
	}
	float Vektor::Betrag(){
		float ergebnis=0.0;
		for(int i=0; i&lt;itsLength;i++){
			ergebnis=ergebnis+(*(itsElement+i)*(*(itsElement+i)));
		}
		return sqrt(ergebnis);
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2144906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2144906</guid><dc:creator><![CDATA[euklid]]></dc:creator><pubDate>Tue, 15 Nov 2011 17:12:25 GMT</pubDate></item><item><title><![CDATA[Reply to Class object dynamic Pointer on Tue, 15 Nov 2011 17:27:22 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int main()
{
   Vektor v;//Konstruktor wird automatisch aufgerufen
   tuwas();
}//Hier wird die lokale Variable v gelöscht und der Destruktor automatisch aufgerufen
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2144909</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2144909</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 15 Nov 2011 17:27:22 GMT</pubDate></item></channel></rss>