<?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[const]]></title><description><![CDATA[<p>Hi ich habe ein paar Probleme mit dem Schluesselwort const. Ich habe eine Funktion und je nachdem ob ich es weglasse oder nciht kompilierts oder nicht. ich hab allerdings keine Ahnung warum oder warum nicht. Folgendes:</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,string check) const {
</code></pre>
<p>So klappt es.</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,string check) {
</code></pre>
<p>So nicht</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,const string check) const {
</code></pre>
<p>So auch nicht</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,string&amp; check) const {
</code></pre>
<p>Und so auch nicht.</p>
<p>Sämtliche Kombinationen aus den &quot;nicht klappenden&quot; Beispielen klappen auch nicht.<br />
Natuerlich weiss ich wofuer const bzw. &amp; gut sind, aber es ist mir nicht erklärlich warum es nicht funktioniert. Und mir ist nicht wirklich klar, wozu ich const hinter den Funktionkopf stelle also</p>
<pre><code class="language-cpp">void foo()const{....
</code></pre>
<p>Ich sende auch mal gleich den kompletten code mit, damit ihr wisst in welchem Zusammenhang das ganze ding läuft:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;functional&gt;
#include&lt;fstream&gt;
#include&lt;vector&gt;
#include&lt;cctype&gt;
#include&lt;iterator&gt;
#include&lt;string&gt;
#include&lt;algorithm&gt;

using namespace std;

struct to_lower : public unary_function&lt;char,char&gt;{ //Lowers the chars
char operator()(const char c){
  return tolower(c);
}
};

template&lt;typename IN,typename OUT, typename PRED&gt;
OUT copy_if (IN cont_beg, IN cont_end, OUT cont, PRED func){   //copy_if with algorithmus mit einer check Funktion func
  while(cont_beg!=cont_end){
      if(func(*cont_beg)){
	*cont=*cont_beg;
	++cont;
	++cont_beg;
      }
    }
    return cont;
}

struct checker : public binary_function&lt;string,string,bool&gt;{ //Die Funktion zum checken
  bool operator()(const string&amp; word,string check) const {   //Hierrum gehts!!!!
for(string::iterator i=check.begin(); i!=check.end() ;++i){
if(word[0]==(*i)) return true;
return false;
}
}
};

int main(int argc, char* argv[]){ //O.K. hier nur wie alles aufgerufen wird.
  fstream file(argv[1]);
  if(!file)cout&lt;&lt;&quot;ERROR&quot;&lt;&lt;endl;
  string word;

  vector&lt;string&gt; vec;
  while(file&gt;&gt;word){
    transform(word.begin(),word.end(),word.begin(),to_lower());
    vec.push_back(word);
  }

copy_if(vec.begin(),vec.end(),ostream_iterator&lt;string&gt;(cout,&quot;\n&quot;),bind2nd(checker(),&quot;abc&quot;));
return 0;
}
</code></pre>
<p>MFG<br />
chewbo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/165337/const</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 13:40:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/165337.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 18 Nov 2006 20:38:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to const on Sat, 18 Nov 2006 20:38:39 GMT]]></title><description><![CDATA[<p>Hi ich habe ein paar Probleme mit dem Schluesselwort const. Ich habe eine Funktion und je nachdem ob ich es weglasse oder nciht kompilierts oder nicht. ich hab allerdings keine Ahnung warum oder warum nicht. Folgendes:</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,string check) const {
</code></pre>
<p>So klappt es.</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,string check) {
</code></pre>
<p>So nicht</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,const string check) const {
</code></pre>
<p>So auch nicht</p>
<pre><code class="language-cpp">bool operator()(const string&amp; word,string&amp; check) const {
</code></pre>
<p>Und so auch nicht.</p>
<p>Sämtliche Kombinationen aus den &quot;nicht klappenden&quot; Beispielen klappen auch nicht.<br />
Natuerlich weiss ich wofuer const bzw. &amp; gut sind, aber es ist mir nicht erklärlich warum es nicht funktioniert. Und mir ist nicht wirklich klar, wozu ich const hinter den Funktionkopf stelle also</p>
<pre><code class="language-cpp">void foo()const{....
</code></pre>
<p>Ich sende auch mal gleich den kompletten code mit, damit ihr wisst in welchem Zusammenhang das ganze ding läuft:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;functional&gt;
#include&lt;fstream&gt;
#include&lt;vector&gt;
#include&lt;cctype&gt;
#include&lt;iterator&gt;
#include&lt;string&gt;
#include&lt;algorithm&gt;

using namespace std;

struct to_lower : public unary_function&lt;char,char&gt;{ //Lowers the chars
char operator()(const char c){
  return tolower(c);
}
};

template&lt;typename IN,typename OUT, typename PRED&gt;
OUT copy_if (IN cont_beg, IN cont_end, OUT cont, PRED func){   //copy_if with algorithmus mit einer check Funktion func
  while(cont_beg!=cont_end){
      if(func(*cont_beg)){
	*cont=*cont_beg;
	++cont;
	++cont_beg;
      }
    }
    return cont;
}

struct checker : public binary_function&lt;string,string,bool&gt;{ //Die Funktion zum checken
  bool operator()(const string&amp; word,string check) const {   //Hierrum gehts!!!!
for(string::iterator i=check.begin(); i!=check.end() ;++i){
if(word[0]==(*i)) return true;
return false;
}
}
};

int main(int argc, char* argv[]){ //O.K. hier nur wie alles aufgerufen wird.
  fstream file(argv[1]);
  if(!file)cout&lt;&lt;&quot;ERROR&quot;&lt;&lt;endl;
  string word;

  vector&lt;string&gt; vec;
  while(file&gt;&gt;word){
    transform(word.begin(),word.end(),word.begin(),to_lower());
    vec.push_back(word);
  }

copy_if(vec.begin(),vec.end(),ostream_iterator&lt;string&gt;(cout,&quot;\n&quot;),bind2nd(checker(),&quot;abc&quot;));
return 0;
}
</code></pre>
<p>MFG<br />
chewbo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176850</guid><dc:creator><![CDATA[chewbo]]></dc:creator><pubDate>Sat, 18 Nov 2006 20:38:39 GMT</pubDate></item><item><title><![CDATA[Reply to const on Sat, 18 Nov 2006 21:30:56 GMT]]></title><description><![CDATA[<p>Hinter dem Methodenkopf bedeutet const, dass die Methode den Zustand eines Objektes nicht ändert. Das heißt, diese Methode darf über eine const Referenz aufgerufen werden.</p>
<p>Edit:<br />
Um die Iteration über Container mit const Referenzen &quot;zu verheiraten&quot;, gibt es const_iterator.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176860</guid><dc:creator><![CDATA[Konstruktör]]></dc:creator><pubDate>Sat, 18 Nov 2006 21:30:56 GMT</pubDate></item><item><title><![CDATA[Reply to const on Sat, 18 Nov 2006 23:04:29 GMT]]></title><description><![CDATA[<p>Letztlich verrät Dir (und uns) der Compiler, warum er etwas nicht compilieren will ....<br />
Kein Forum kann Compiler-Meldungen ersetzen - aber es kann helfen, sie zu verstehen ... wenn man sie denn zur Verfügung stellt. <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>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1176897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1176897</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Sat, 18 Nov 2006 23:04:29 GMT</pubDate></item></channel></rss>