title: use of an overloaded operator in a constructor?
body: <p>i'm writing a program where you can give an object an integer and it calculates the next bigger prime number. The task is to overload the prefix operator and use it in the constructor, so that if i create an object and give it the number 11, it should store the next bigger prime number (13). </p>
  
  <p>my operator overload looks like this: </p>
  
  <pre class="lang-cpp prettyprint-override"><code>cPrimZahl&amp; cPrimZahl::operator++()
  {
      nextprim = prim;
      while (!is_Prime(nextprim))
      {
          ++nextprim;
          if (nextprim &gt; 10000)
          {
              while (!is_Prime(nextprim))
              {
                  --nextprim;
              }
              prim = nextprim;
              break;
          }
          prim = nextprim;
      }
  
      cout &lt;&lt; "die naechst groessere Primzahl ist: " &lt;&lt; prim &lt;&lt; endl;
  
      return *this;
  }
  </code></pre>
  
  <p>main:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main(){
      cPrimZahl obj(13);  // The object here is 13 now
      ++obj1;             // Here its 17
  
      return 0;
  }
  </code></pre>
  
  <p>my constructor:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>cPrimZahl::cPrimZahl(int prim_in)
  {
      if (prim_in &gt; maxprim)  // maxprim = 10000
      {
          cout &lt;&lt; "Prime number is to big! Adjusting..." &lt;&lt; endl;
          prim = 1;
      }
  
      else if (prim_in &lt; 0)
      {
          cout &lt;&lt; "Prime number can't be negative! Adjusting..." &lt;&lt; endl;
          prim = 1;
      }
  
      prim = prim_in;
      ++prim;   // at this point i want it to increment to give me the next bigger prime number
  }
  
  </code></pre>
  
  <p>i tried a lot of methods now but i just always get a regular increment... The operator overload comes before the construcot, but i also tried to put the constructor before the overload, neither works. What else can i do?</p>