<?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[Konstante member eine klasse]]></title><description><![CDATA[<pre><code class="language-cpp">class foo{

 const vector&lt;int&gt; m_Dat;

  foo(int i=0) : m_Dat(i){

     m_Dat.pushback(....);
     m_Dat.pushback(....);
     m_Dat.pushback(....);

  }

};
</code></pre>
<p>das problem ist nun, das m_Dat nach dem konstruktor schon konstant bleiben soll, aber im Konstruktor will ich noch default Werte hinzufügen.. geht das irgendwie, oder muss ich &quot;const &quot; weg lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/217588/konstante-member-eine-klasse</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 14:48:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/217588.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Jul 2008 03:39:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Konstante member eine klasse on Wed, 09 Jul 2008 03:39:11 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">class foo{

 const vector&lt;int&gt; m_Dat;

  foo(int i=0) : m_Dat(i){

     m_Dat.pushback(....);
     m_Dat.pushback(....);
     m_Dat.pushback(....);

  }

};
</code></pre>
<p>das problem ist nun, das m_Dat nach dem konstruktor schon konstant bleiben soll, aber im Konstruktor will ich noch default Werte hinzufügen.. geht das irgendwie, oder muss ich &quot;const &quot; weg lassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1543870</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1543870</guid><dc:creator><![CDATA[C++Lehrling!=Noob]]></dc:creator><pubDate>Wed, 09 Jul 2008 03:39:11 GMT</pubDate></item><item><title><![CDATA[Reply to Konstante member eine klasse on Wed, 09 Jul 2008 05:44:14 GMT]]></title><description><![CDATA[<p>du könntest eine funktion schreiben, die einen vector zurückgibt und damit deinen konstanten vector initialisieren:</p>
<pre><code class="language-cpp">class Foo
{
  const vector&lt;int&gt; dat;
  static vector&lt;int&gt; init_dat ()
  {
     vector&lt;int&gt; tmp;
     tmp.push_back(42);
     return tmp;
  }

public:
  Foo () : dat(init_dat())
  { }
};
</code></pre>
<p>andererseits könntest du dir auch bestimmte werte für den vector generieren lassen, à la boost::counting_iterator:</p>
<pre><code class="language-cpp">class Foo
{
  const vector&lt;int&gt; v;

public:
  Foo () : v(boost::counting_iterator&lt;int&gt;(0), 
             boost::counting_iteraotr&lt;int&gt;(5))
  { }
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1543890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1543890</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Wed, 09 Jul 2008 05:44:14 GMT</pubDate></item></channel></rss>