<?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[Geht ofstream als &amp;quot;private&amp;quot;]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe folgendes Problem:</p>
<p>Ich bin dabei eine Klasse zu schreiben, die als Objekte Textdateien(VRML-Code) erstellt und diese fortführen kann.</p>
<pre><code class="language-cpp">#include&lt;fstream&gt;
#include&lt;iostream&gt;
#include &quot;Rotationparameter.h&quot;
#include &quot;Cylinder.h&quot;

using namespace std;

#ifndef _PAINTWRL_
#define _PAINTWRL_
class PaintWrl {
private:
	//kann man hier einen Stream als &quot;private&quot; deklarieren
        //z.B. so: static ofstream fileToWrl(&quot;MyFile.wrl&quot;);

public:

	/********** Defaultkonstruktor **********/
	PaintWrl();

	static void CylinderToWrl(Rotationparameter &amp;MyRotation, Cylinder &amp;MyCylinder);

};
#endif	// _PAINTWRL_
</code></pre>
<p>Die dazugehörige CPP:</p>
<pre><code class="language-cpp">//Datei mit dem Namen PaintWrl.cpp
#include &quot;PaintWrl.h&quot;
using namespace std;
/********** Defaultkonstruktor **********/
PaintWrl::PaintWrl()
{
	/********** Definition der VRML - Datei **********/
	fileToWrl &lt;&lt; &quot;#VRML V2.0 utf8&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\nBackground&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t{&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\tskyColor &quot; &lt;&lt; 1 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t}&quot; &lt;&lt; endl;
}

static void CylinderToWrl(Rotationparameter &amp;MyRotation, Cylinder &amp;MyCylinder)
{
    if(!fileToWrl.is_open())
       return;  

	Point3d TransPoint;
	TransPoint = MyCylinder.getStart();

        fileToWrl &lt;&lt; &quot;\nTransform&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t{&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t.................................&quot; &lt;&lt; endl;
}
</code></pre>
<p>Dies wird dann so aufgerufen:</p>
<pre><code class="language-cpp">//main.cpp
...
PaintWrl Stephan;
Stephan.CylinderToWrl(CylRotation, Testcylinder);
</code></pre>
<p>Das funktioniert leider überhaupt nicht ...<br />
Bin für jedes praktische Beispiel Dankbar <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="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/188675/geht-ofstream-als-quot-private-quot</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 04:19:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/188675.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Aug 2007 19:28:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Geht ofstream als &amp;quot;private&amp;quot; on Thu, 02 Aug 2007 19:28:00 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe folgendes Problem:</p>
<p>Ich bin dabei eine Klasse zu schreiben, die als Objekte Textdateien(VRML-Code) erstellt und diese fortführen kann.</p>
<pre><code class="language-cpp">#include&lt;fstream&gt;
#include&lt;iostream&gt;
#include &quot;Rotationparameter.h&quot;
#include &quot;Cylinder.h&quot;

using namespace std;

#ifndef _PAINTWRL_
#define _PAINTWRL_
class PaintWrl {
private:
	//kann man hier einen Stream als &quot;private&quot; deklarieren
        //z.B. so: static ofstream fileToWrl(&quot;MyFile.wrl&quot;);

public:

	/********** Defaultkonstruktor **********/
	PaintWrl();

	static void CylinderToWrl(Rotationparameter &amp;MyRotation, Cylinder &amp;MyCylinder);

};
#endif	// _PAINTWRL_
</code></pre>
<p>Die dazugehörige CPP:</p>
<pre><code class="language-cpp">//Datei mit dem Namen PaintWrl.cpp
#include &quot;PaintWrl.h&quot;
using namespace std;
/********** Defaultkonstruktor **********/
PaintWrl::PaintWrl()
{
	/********** Definition der VRML - Datei **********/
	fileToWrl &lt;&lt; &quot;#VRML V2.0 utf8&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\nBackground&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t{&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\tskyColor &quot; &lt;&lt; 1 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; &quot; &quot; &lt;&lt; 1 &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t}&quot; &lt;&lt; endl;
}

static void CylinderToWrl(Rotationparameter &amp;MyRotation, Cylinder &amp;MyCylinder)
{
    if(!fileToWrl.is_open())
       return;  

	Point3d TransPoint;
	TransPoint = MyCylinder.getStart();

        fileToWrl &lt;&lt; &quot;\nTransform&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t{&quot; &lt;&lt; endl;
	fileToWrl &lt;&lt; &quot;\t.................................&quot; &lt;&lt; endl;
}
</code></pre>
<p>Dies wird dann so aufgerufen:</p>
<pre><code class="language-cpp">//main.cpp
...
PaintWrl Stephan;
Stephan.CylinderToWrl(CylRotation, Testcylinder);
</code></pre>
<p>Das funktioniert leider überhaupt nicht ...<br />
Bin für jedes praktische Beispiel Dankbar <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="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1337620</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1337620</guid><dc:creator><![CDATA[Stephan_lernt_C++]]></dc:creator><pubDate>Thu, 02 Aug 2007 19:28:00 GMT</pubDate></item><item><title><![CDATA[Reply to Geht ofstream als &amp;quot;private&amp;quot; on Thu, 02 Aug 2007 19:34:38 GMT]]></title><description><![CDATA[<p>Stephan_lernt_C++ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">class PaintWrl
{
    //kann man hier einen Stream als &quot;private&quot; deklarieren
    //z.B. so: static ofstream fileToWrl(&quot;MyFile.wrl&quot;);
};
</code></pre>
</blockquote>
<p>Ich hab's mal auf das wesentliche gekürzt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
<p>Das geht schon, aber nicht so. Zu ersteinmal solltest du dir bewusst machen, was static heißt. Bist du dir sicher, dass du das haben willst?</p>
<p>Wenn ja, dann muss der Konstruktoraufruf (sprich die Definition) in einer(!) Implementierungsdatei stehen, in etwa so:</p>
<pre><code class="language-cpp">#include &quot;PaintWrl.hpp&quot;
// ...
std::ofstream PaintWrl::fileToWrl (&quot;MyFile.wrl&quot;);
</code></pre>
<p>Ach ja, bitte <strong>NIEMALS</strong> &quot;using namespace&quot; im Header. Das macht das Klima kaputt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1337625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1337625</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Thu, 02 Aug 2007 19:34:38 GMT</pubDate></item><item><title><![CDATA[Reply to Geht ofstream als &amp;quot;private&amp;quot; on Thu, 02 Aug 2007 19:48:43 GMT]]></title><description><![CDATA[<p>Also ich meinte folgendes:</p>
<pre><code class="language-cpp">//Test.h
class Test{
private:
ofstream fileTest(&quot;MyFile.wrl&quot;);
public:
Test();
void vielText(double a,double b);
};
</code></pre>
<pre><code class="language-cpp">//Test.cpp
Test::Test()
{
fileTest &lt;&lt; &quot;Header...&quot; &lt;&lt; endl;
}
void vielText(double a,double b)
{
fileTest &lt;&lt; &quot;Werte für a &quot; &lt;&lt; a &lt;&lt; endl;
fileTest &lt;&lt; &quot;Werte für b &quot; &lt;&lt; b &lt;&lt; endl;
}
</code></pre>
<pre><code class="language-cpp">//main.cpp
Test Versuch_1;
Versuch_1.vielText(c,d);
</code></pre>
<p>Geht sowas? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1337631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1337631</guid><dc:creator><![CDATA[Stephan_lernt_C++]]></dc:creator><pubDate>Thu, 02 Aug 2007 19:48:43 GMT</pubDate></item><item><title><![CDATA[Reply to Geht ofstream als &amp;quot;private&amp;quot; on Thu, 02 Aug 2007 19:54:19 GMT]]></title><description><![CDATA[<p>Nein. Der Konstruktoraufruf für fileTest /muss/ im Konstruktor von Test sein. Schließlich hat jedes Test-Objekt ein eigenes fileTest-Objekt, das initialisiert werden will.</p>
<p>=&gt;</p>
<pre><code class="language-cpp">// Test.cpp
Test () : fileTest (&quot;MyFile.wrl&quot;)
{
    // etc. pp.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1337635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1337635</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Thu, 02 Aug 2007 19:54:19 GMT</pubDate></item><item><title><![CDATA[Reply to Geht ofstream als &amp;quot;private&amp;quot; on Thu, 02 Aug 2007 20:10:31 GMT]]></title><description><![CDATA[<p>Jetzt funktionierts <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1337653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1337653</guid><dc:creator><![CDATA[Stephan_lernt_C++]]></dc:creator><pubDate>Thu, 02 Aug 2007 20:10:31 GMT</pubDate></item></channel></rss>