<?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ängerproblem]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich bin ein C++ Neuling und habe ein (Noob-)Problem.</p>
<p>Ich habe eine Klasse erstellt</p>
<pre><code>class kegel 
{
	float h, r1, r2, pi;

	public:
		kegel(float h=10.0f, float r1=5.0f, float r2=0.0f, static double pi=4.0*atan(1.0)):h(h), r1(r1), r2(r2), pi(pi)
		{
			cout	&lt;&lt;&quot;Konstruktor kegel\n&quot;
					&lt;&lt;&quot;h = &quot;&lt;&lt;this-&gt;h
					&lt;&lt;&quot;\nr1 = &quot;&lt;&lt;this-&gt;r1
					&lt;&lt;&quot;\nr2 = &quot;&lt;&lt;this-&gt;r2&lt;&lt;endl;
		}
         ~kegel()
		{
			h=10.0f; r1=5.0f; r2=0.0f;
			cout	&lt;&lt;&quot;\nDestruktor kegel\n&quot;&lt;&lt;endl;
		}
}
</code></pre>
<p>und möchte nun im Main die Wert h ausgeben (auf der Console).<br />
Wie bekomme ich das hin ohne noch weiteren Code in die Klasse zu scheiben zu müssen?</p>
<p>So scheint es ja nicht zu funktionieren:</p>
<pre><code>void main()
{
	kegel k;
	k.ein();
	cout.flags(ios::fixed);
	cout&lt;&lt;setprecision(4)&lt;&lt;&quot;\nh  = &quot;&lt;&lt;setw(10)&lt;&lt;k-&gt;h; // &lt;- hier soll h ausgegeben werden
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/236923/anfängerproblem</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 15:35:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/236923.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Mar 2009 21:29:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Anfängerproblem on Sat, 21 Mar 2009 21:29:15 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich bin ein C++ Neuling und habe ein (Noob-)Problem.</p>
<p>Ich habe eine Klasse erstellt</p>
<pre><code>class kegel 
{
	float h, r1, r2, pi;

	public:
		kegel(float h=10.0f, float r1=5.0f, float r2=0.0f, static double pi=4.0*atan(1.0)):h(h), r1(r1), r2(r2), pi(pi)
		{
			cout	&lt;&lt;&quot;Konstruktor kegel\n&quot;
					&lt;&lt;&quot;h = &quot;&lt;&lt;this-&gt;h
					&lt;&lt;&quot;\nr1 = &quot;&lt;&lt;this-&gt;r1
					&lt;&lt;&quot;\nr2 = &quot;&lt;&lt;this-&gt;r2&lt;&lt;endl;
		}
         ~kegel()
		{
			h=10.0f; r1=5.0f; r2=0.0f;
			cout	&lt;&lt;&quot;\nDestruktor kegel\n&quot;&lt;&lt;endl;
		}
}
</code></pre>
<p>und möchte nun im Main die Wert h ausgeben (auf der Console).<br />
Wie bekomme ich das hin ohne noch weiteren Code in die Klasse zu scheiben zu müssen?</p>
<p>So scheint es ja nicht zu funktionieren:</p>
<pre><code>void main()
{
	kegel k;
	k.ein();
	cout.flags(ios::fixed);
	cout&lt;&lt;setprecision(4)&lt;&lt;&quot;\nh  = &quot;&lt;&lt;setw(10)&lt;&lt;k-&gt;h; // &lt;- hier soll h ausgegeben werden
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1684015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684015</guid><dc:creator><![CDATA[N0Sferatu]]></dc:creator><pubDate>Sat, 21 Mar 2009 21:29:15 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem on Sat, 21 Mar 2009 21:43:26 GMT]]></title><description><![CDATA[<p>Hier mal eine lauffähige Variante:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;cmath&gt;

using namespace std;

class kegel 
{ 
	float h_, r1_, r2_, pi_; 

public: 
	kegel(float h=10.0f, float r1=5.0f, float r2=0.0f, float pi=4.0*atan(1.0))
	: h_(h), r1_(r1), r2_(r2), pi_(pi)
	{ 
		cout	&lt;&lt; &quot;Konstruktor kegel\n&quot; 
				&lt;&lt; &quot;h = &quot; &lt;&lt; this-&gt;h_ 
				&lt;&lt; &quot;\nr1 = &quot; &lt;&lt; this-&gt;r1_ 
				&lt;&lt; &quot;\nr2 = &quot; &lt;&lt; this-&gt;r2_ &lt;&lt; endl; 
	} 
	~kegel() 
	{ 
		cout &lt;&lt; &quot;\nDestruktor kegel\n&quot; &lt;&lt; endl; 
	}

	float gibHoehe() const
	{
		return this-&gt;h_;
	}
};

int main()
{
	kegel k;
	cout.flags(ios::fixed); 
	cout&lt;&lt;setprecision(4) &lt;&lt; &quot;\nh  = &quot; &lt;&lt; setw(10)&lt;&lt; k.gibHoehe();
}
</code></pre>
<p>1. Benutzte bitte C++ Tags<br />
2. Ist das hier leider das falsche Forum (C++ wäre korrekt).<br />
3. Verwende für Member Variablen (z.B. h_) einen anderen Namen als für ein Argument (wie z.B. h).<br />
4. Am Ende der Klassen Definition fehlt ein ;</p>
<p>Gruss Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1684023</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684023</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Sat, 21 Mar 2009 21:43:26 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem on Sun, 22 Mar 2009 08:35:34 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-18363.html" rel="nofollow">Jochen Kalmbach</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-58.html" rel="nofollow">C++/CLI mit .NET</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1684137</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684137</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 22 Mar 2009 08:35:34 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem on Sun, 22 Mar 2009 17:43:13 GMT]]></title><description><![CDATA[<p>Vielen Dank für die überaus schnelle Hilfe!</p>
<p>Ich habe noch eine weiter Frage zu diesem Thema:<br />
Ist es auch möglich im Main die Variable h (von k) auszugeben ohne in der Klasse weitern Code (wie im Beispiel &quot;gibHoehe&quot;) zu schreiben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1684392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684392</guid><dc:creator><![CDATA[N0Sferatu]]></dc:creator><pubDate>Sun, 22 Mar 2009 17:43:13 GMT</pubDate></item><item><title><![CDATA[Reply to Anfängerproblem on Sun, 22 Mar 2009 17:48:34 GMT]]></title><description><![CDATA[<p>N0Sferatu schrieb:</p>
<blockquote>
<p>Ist es auch möglich im Main die Variable h (von k) auszugeben ohne in der Klasse weitern Code (wie im Beispiel &quot;gibHoehe&quot;) zu schreiben?</p>
</blockquote>
<p>Du könntest die Variable öffentlich machen und direkt darauf zugreifen. Allerdings rate ich dir nicht dazu, da damit die Kapselung verloren geht. So schlimm ist der Code für die Memberfunktion ja nicht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1684394</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1684394</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 22 Mar 2009 17:48:34 GMT</pubDate></item></channel></rss>