<?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[Read only erwünscht!]]></title><description><![CDATA[<p>Folgendes Problem:</p>
<p><strong>Header:</strong></p>
<pre><code class="language-cpp">#ifndef included_random_h
#define included_random_h

#include &quot;square.h&quot;

extern uint64 random_white_pawn[SQUARES];
extern uint64 random_white_knight[SQUARES];
extern uint64 random_white_bishop[SQUARES];
extern uint64 random_white_rook[SQUARES];
extern uint64 random_white_queen[SQUARES];
extern uint64 random_white_king[SQUARES];

// much more...

extern void random_initialize(void);

#endif
</code></pre>
<p>Die Arrays werden in einem source-code File initialisiert und *sollen<br />
*anschliessend nur noch <strong>read only</strong> sein.</p>
<p><strong>Kann natürlich in der Header schreiben:</strong></p>
<pre><code class="language-cpp">inline uint64 random_get_white_pawn(const sintx square) {
  return random_white_pawn[square];
}
</code></pre>
<p>Ist aber nicht wirklich gut, da die Arrays immer noch <em>frei herumklaufen</em>.</p>
<p><strong>Schlechte Lösung:</strong></p>
<p>Ich baue eine Klasse:</p>
<pre><code class="language-cpp">#ifndef included_random_h
#define included_random_h

#include &quot;square.h&quot;

class Random {
private:
  static uint64 random_white_pawn[SQUARES];
  static uint64 random_white_knight[SQUARES];
  static uint64 random_white_bishop[SQUARES];
  static uint64 random_white_rook[SQUARES];
  static uint64 random_white_queen[SQUARES];
  static uint64 random_white_king[SQUARES];
  // much more...

public: 
  static void random_initialize(void);
  static uint64 random_get_white_pawn(const sintx square);
  // much more...
};

inline uint64 Random::random_get_white_pawn(const sintx square) {
  return random_white_pawn[square];
}

// much more...

#endif
</code></pre>
<p>Da mal wieder alles static ist und es keine Instanzen dieser <em>read-only</em> Klasse gibt, ist das auch nicht das gelbe vom Ei.</p>
<p>Was habe ich für eine Möglichkeit einen sauberen read-only Mechanismus zu <em>erzwingen</em>?</p>
<p><strong>Danke!</strong></p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252353/read-only-erwünscht</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 14:32:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252353.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 18 Oct 2009 18:09:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Read only erwünscht! on Sun, 18 Oct 2009 18:09:30 GMT]]></title><description><![CDATA[<p>Folgendes Problem:</p>
<p><strong>Header:</strong></p>
<pre><code class="language-cpp">#ifndef included_random_h
#define included_random_h

#include &quot;square.h&quot;

extern uint64 random_white_pawn[SQUARES];
extern uint64 random_white_knight[SQUARES];
extern uint64 random_white_bishop[SQUARES];
extern uint64 random_white_rook[SQUARES];
extern uint64 random_white_queen[SQUARES];
extern uint64 random_white_king[SQUARES];

// much more...

extern void random_initialize(void);

#endif
</code></pre>
<p>Die Arrays werden in einem source-code File initialisiert und *sollen<br />
*anschliessend nur noch <strong>read only</strong> sein.</p>
<p><strong>Kann natürlich in der Header schreiben:</strong></p>
<pre><code class="language-cpp">inline uint64 random_get_white_pawn(const sintx square) {
  return random_white_pawn[square];
}
</code></pre>
<p>Ist aber nicht wirklich gut, da die Arrays immer noch <em>frei herumklaufen</em>.</p>
<p><strong>Schlechte Lösung:</strong></p>
<p>Ich baue eine Klasse:</p>
<pre><code class="language-cpp">#ifndef included_random_h
#define included_random_h

#include &quot;square.h&quot;

class Random {
private:
  static uint64 random_white_pawn[SQUARES];
  static uint64 random_white_knight[SQUARES];
  static uint64 random_white_bishop[SQUARES];
  static uint64 random_white_rook[SQUARES];
  static uint64 random_white_queen[SQUARES];
  static uint64 random_white_king[SQUARES];
  // much more...

public: 
  static void random_initialize(void);
  static uint64 random_get_white_pawn(const sintx square);
  // much more...
};

inline uint64 Random::random_get_white_pawn(const sintx square) {
  return random_white_pawn[square];
}

// much more...

#endif
</code></pre>
<p>Da mal wieder alles static ist und es keine Instanzen dieser <em>read-only</em> Klasse gibt, ist das auch nicht das gelbe vom Ei.</p>
<p>Was habe ich für eine Möglichkeit einen sauberen read-only Mechanismus zu <em>erzwingen</em>?</p>
<p><strong>Danke!</strong></p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1794363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1794363</guid><dc:creator><![CDATA[Tomahawk]]></dc:creator><pubDate>Sun, 18 Oct 2009 18:09:30 GMT</pubDate></item><item><title><![CDATA[Reply to Read only erwünscht! on Sun, 18 Oct 2009 18:18:39 GMT]]></title><description><![CDATA[<p>vielleicht sowas:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
using namespace std;

int const SQUARES=4;

int const (&amp;init_rwp())[SQUARES]{
	static int feld[SQUARES];
	feld[0]=47;
	feld[1]=11;
	feld[2]=1;
	feld[3]=2;
	return feld;
}

int const (&amp;random_white_pawn)[SQUARES]=init_rwp();

int main(){
	cout&lt;&lt;random_white_pawn[1]&lt;&lt;'\n';
	cout&lt;&lt;sizeof(random_white_pawn)&lt;&lt;'\n';
//	random_white_pawn[1]=2;//geht nicht
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1794366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1794366</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 18 Oct 2009 18:18:39 GMT</pubDate></item><item><title><![CDATA[Reply to Read only erwünscht! on Sun, 18 Oct 2009 18:23:33 GMT]]></title><description><![CDATA[<p>Ich lege vielleicht falsch, aber sowas Einfaches:</p>
<pre><code class="language-cpp">extern const uint64 random_white_pawn[SQUARES];
extern const uint64 random_white_knight[SQUARES];
extern const uint64 random_white_bishop[SQUARES];
extern const uint64 random_white_rook[SQUARES];
extern const uint64 random_white_queen[SQUARES];
extern const uint64 random_white_king[SQUARES];
</code></pre>
<p>Andere Datei:</p>
<pre><code class="language-cpp">const uint64 random_white_pawn[SQUARES] = {...};
...
</code></pre>
<p>funktioniert nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1794372</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1794372</guid><dc:creator><![CDATA[CppCoder]]></dc:creator><pubDate>Sun, 18 Oct 2009 18:23:33 GMT</pubDate></item><item><title><![CDATA[Reply to Read only erwünscht! on Sun, 18 Oct 2009 18:32:46 GMT]]></title><description><![CDATA[<p>CppCoder schrieb:</p>
<blockquote>
<p>Ich lege vielleicht falsch, aber sowas Einfaches:</p>
<pre><code class="language-cpp">extern const uint64 random_white_pawn[SQUARES];
extern const uint64 random_white_knight[SQUARES];
extern const uint64 random_white_bishop[SQUARES];
extern const uint64 random_white_rook[SQUARES];
extern const uint64 random_white_queen[SQUARES];
extern const uint64 random_white_king[SQUARES];
</code></pre>
<p>Andere Datei:</p>
<pre><code class="language-cpp">const uint64 random_white_pawn[SQUARES] = {...};
...
</code></pre>
<p>funktioniert nicht?</p>
</blockquote>
<p>Doch, geht.<br />
Ich ging davon aus, daß eine Funktion das Initialisieren machen muß.<br />
Aber wenn ich's recht bedenke, werden das wohl die magic numbers für's zobrist hashing, die können gern fertig vorausberechnet sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1794376</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1794376</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 18 Oct 2009 18:32:46 GMT</pubDate></item><item><title><![CDATA[Reply to Read only erwünscht! on Sun, 18 Oct 2009 18:33:40 GMT]]></title><description><![CDATA[<p>[cpp]<br />
class MyClass<br />
{<br />
public:<br />
static MyClass&amp; GetInstance() const<br />
{<br />
return m_instance;<br />
}</p>
<p>const uint64 GetRandomWhitePawn() const<br />
{<br />
return random_white_pawn [SQUARES];<br />
}</p>
<p>private:<br />
MyClass m_instance;<br />
uint64 random_white_pawn[SQUARES];<br />
MyClass(){}<br />
};<br />
[/const]<br />
?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1794377</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1794377</guid><dc:creator><![CDATA[C++R00ki3]]></dc:creator><pubDate>Sun, 18 Oct 2009 18:33:40 GMT</pubDate></item><item><title><![CDATA[Reply to Read only erwünscht! on Sun, 18 Oct 2009 18:41:45 GMT]]></title><description><![CDATA[<blockquote>
<p>daß eine Funktion das Initialisieren machen muß.</p>
</blockquote>
<p>Kann es vielleicht eine template-basierende Compile-time Funktion sein?<br />
Das liegt ganz klar an Schwierigkeitsgrad der Funktion selbst.</p>
<p>PS In neuem C++0x Standard kann man eine Funktion als constexpr definieren. dann wird so was:</p>
<pre><code class="language-cpp">const uint64 myvar = funcA()
</code></pre>
<p>auch möglich sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1794381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1794381</guid><dc:creator><![CDATA[CppCoder]]></dc:creator><pubDate>Sun, 18 Oct 2009 18:41:45 GMT</pubDate></item></channel></rss>