<?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[Package access in C++]]></title><description><![CDATA[<p>Gibt es sowas wie package access von Java auch in C++?</p>
<p>Ich will zB eine Klasse Sound und eine SoundManager. Ne Instanz von Sound soll aber nur vom SoundManager erzeugt werden können. Eine Möglichkeit wäre Sound als private Klasse von SoundManager zu definieren, aber dann hab ich Sound nur als Unterklasse. Ich würde lieber so eine Einschränkung wie bei Package access haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/124490/package-access-in-c</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 23:47:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/124490.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Oct 2005 05:57:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Package access in C++ on Fri, 28 Oct 2005 05:57:34 GMT]]></title><description><![CDATA[<p>Gibt es sowas wie package access von Java auch in C++?</p>
<p>Ich will zB eine Klasse Sound und eine SoundManager. Ne Instanz von Sound soll aber nur vom SoundManager erzeugt werden können. Eine Möglichkeit wäre Sound als private Klasse von SoundManager zu definieren, aber dann hab ich Sound nur als Unterklasse. Ich würde lieber so eine Einschränkung wie bei Package access haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/902385</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/902385</guid><dc:creator><![CDATA[Sag i net]]></dc:creator><pubDate>Fri, 28 Oct 2005 05:57:34 GMT</pubDate></item><item><title><![CDATA[Reply to Package access in C++ on Fri, 28 Oct 2005 06:16:01 GMT]]></title><description><![CDATA[<p>Ja, nennt sich in C++ halt Namespace.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/902396</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/902396</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Fri, 28 Oct 2005 06:16:01 GMT</pubDate></item><item><title><![CDATA[Reply to Package access in C++ on Fri, 28 Oct 2005 06:16:21 GMT]]></title><description><![CDATA[<p>Das beste, was du machen kannst, sind namespaces und friend-Zugriff:</p>
<pre><code class="language-cpp">class SoundManager;
class Sound
{
public:
  //wichtige Zugriffsfunktionen
  friend class SoundManager;
private:
  Sound();
  //alle weiteren Konstruktoren landen hier
};

class SoundManager
{
public:
  SoundManager():data(0){}
  SoundManager(int s_count):data(s_count,Sound()){}
  //weitere Konstruktoren und Zugriffsfunktionen
private:
  vector&lt;Sound&gt; data;
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/902397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/902397</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 28 Oct 2005 06:16:21 GMT</pubDate></item><item><title><![CDATA[Reply to Package access in C++ on Fri, 28 Oct 2005 06:20:36 GMT]]></title><description><![CDATA[<p>Hallo,<br />
direkt gibt es sowas nicht. Deinen Fall kannst du aber mindestens auf zwei Arten simulieren.<br />
a) friends: Du machst die Konstruktoren von Sound private und SoundManager zu einem Freund von Sound.</p>
<p>b) Trennung von Interface und Implementation: Du erstellst für Sound ein Interface (eine abstrakte Klasse in C++) und implementierst eine Klasse die dieses Interface erfüllt in der cpp-Datei von SoundManager (in einem anonymen Namespace).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/902401</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/902401</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Fri, 28 Oct 2005 06:20:36 GMT</pubDate></item><item><title><![CDATA[Reply to Package access in C++ on Fri, 28 Oct 2005 08:59:49 GMT]]></title><description><![CDATA[<p>Das mit den fried Klassen ist ganz interessant, aber wie sollen mir namespaces helfen. Gibt es sowas wie namesapce access?</p>
<p>Ein Interface wollte ich sowieso verwenden.</p>
<p>Danke erst mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/902528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/902528</guid><dc:creator><![CDATA[Sag i net]]></dc:creator><pubDate>Fri, 28 Oct 2005 08:59:49 GMT</pubDate></item><item><title><![CDATA[Reply to Package access in C++ on Fri, 28 Oct 2005 09:08:46 GMT]]></title><description><![CDATA[<p>Nein, der Inhalt eines Namensraumes ist von außen frei zugänglich. Aber ein anonymer Namespace kann nur aus der aktuellen Übersetzungseinheit angesprochen werden:</p>
<pre><code class="language-cpp">//SoundMan.h

class SoundInterface
{
  //abstrakte Klasse
}

class SoundManager
{
  //...
  // verweist notfalls auf SoundInterface
};

//SoundMan.cpp
#include &quot;SoundMan.h&quot;
namespace
{
  class Sound:public SoundInterface
  {
    //...
    //überschreibt pur virtuelle Methoden
  };
}

//SoundManager-Methoden: nutzen virtuelle Methoden von SoundInterface, erzeugen aber bei Bedarf Sound-Objekte
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/902541</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/902541</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Fri, 28 Oct 2005 09:08:46 GMT</pubDate></item><item><title><![CDATA[Reply to Package access in C++ on Fri, 28 Oct 2005 11:50:49 GMT]]></title><description><![CDATA[<p>Dann ist es doch wieder so wie ne private Klasse Sound, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/902724</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/902724</guid><dc:creator><![CDATA[Sag i net]]></dc:creator><pubDate>Fri, 28 Oct 2005 11:50:49 GMT</pubDate></item></channel></rss>