title: operator changing the argument of class for no reason (*int)
body: <p>In my class File, I've:</p>
  
  <pre><code>class File
  {
      std::vector&lt;char&gt; name, timeOfCreation, timeOfLastEdit, content;
      std::vector&lt;char&gt;::const_iterator* pPos, *pPosOfEnd;
      int *pSize;
      bool *pForcedSize;
      void setTimeOfLastEdit();
      int* indexOfLastChar, *indexOfCurrentChar;
  
      friend class Interface;
      friend class Directory;
  public:
      File(std::string, int argSize = 0, std::string arg_content = 0); // constructor
      File(); // constructor
      File(const File&amp;); // copy constructor
      ~File(); // destructor
      char* returnName(); 
  
      File&amp; operator = (const File&amp;);
      File operator += (const int);
      File operator -= (const int);
      File&amp; operator ++ (); // prefix
      File&amp; operator -- (); // prefix
      File operator ++ (int); // postfix
      File operator -- (int); // postfix
  
      bool operator ! ();
  
      int operator () (char*, int);
  
      friend  bool operator == (const File&amp;, const File&amp;);
      friend  bool operator != (const File&amp;, const File&amp;);
      friend  bool operator &gt;= (const File&amp;, const File&amp;);
      friend  bool operator &lt;= (const File&amp;, const File&amp;);
      friend  bool operator &lt; (const File&amp;, const File&amp;);
      friend  bool operator &gt; (const File&amp;, const File&amp;);
  
      friend std::istream &amp; operator &gt;&gt; (std::istream&amp;, File&amp;);
      friend std::ostream &amp; operator &lt;&lt; (std::ostream&amp;, File);
  
  };
  </code></pre>
  
  <p>and my operator () is like this:</p>
  
  <pre><code>int File::operator () (char* contentNextNBytes, int n)
  {
      int i; int j = 0;
      std::vector&lt;char&gt;::const_iterator it = content.begin();
      for(j = 0; j &lt; *indexOfCurrentChar; j++)
          ++it;
  
      for(i = 0; i &lt; n; i++)
      {
          contentNextNBytes[i] = *it;
          if(i == *indexOfLastChar-1) 
          {
              contentNextNBytes[i+1] = '\0';
              *indexOfCurrentChar = i+1;
              return i+1;
          }
          ++it;
      }
  
      contentNextNBytes[i] = '\0';
      *indexOfCurrentChar = n;
      return n;
  }
  </code></pre>
  
  <p>In my other class, Interface, I call the operator () with <code>int i = dir[index](buffer, n)</code>, where n is num of bytes, and index is the index of the File in directory. </p>
  
  <p>Now, as is implemented in the operator, the value *indexOfCurrentChar points to should (and does) become the position of the last character extracted from the File. However when I call the same operator again, for the same index, with <code>int j = dir[index](buffer, n1)</code>, right when the program enters the operator {} it changes the value of *indexOfCurrentChar to 0 again, while my code should continue from the last char and read the next n1 bytes in File</p>
  
  <p>Why does this happen? :(</p>
  
  <p>Here's part of the code I'm using to call the operator in the class Interface:</p>
  
  <pre><code> buffer = new char[n+1];
      k = d[index](buffer, n);
      std::cout&lt;&lt;"Extracting of "&lt;&lt;k&lt;&lt;" bytes succeeded, and here is the content extracted:\n";
  std::cout&lt;&lt;"\""&lt;&lt;buffer&lt;&lt;"\"";
  </code></pre>
  
  <p>Edit1: Here's where I change my indexOfCurrentChar:</p>
  
  <p>1) In the assignment operator =   (however, I'm not calling it in my Interface class)
  2) In the copy constructor  (Also not using it in Interface class, and it just copies the value)
  3) In the File constructor:</p>
  
  <pre><code>File::File()
  {
      // stuff
      indexOfCurrentChar = new int;
  } //I'm not setting its value, just allocating memory
  </code></pre>
  
  <p>4) In the File constructor:</p>
  
  <pre><code>File::File(std::string arg_name, int arg_size, std::string arg_content)
  {
       // stuff
       indexOfCurrentChar = new int;
       *indexOfCurrentChar = 0;
      //setting it to 0, but its just at creation time
  }
  </code></pre>
  
  <p>5) In the >> operator
  //getting file content</p>
  
  <pre><code>std::cout&lt;&lt;"Enter file content: ";
      *object.indexOfCurrentChar = 0;
      while( in.get(c) &amp;&amp; c != '\n');
      i = 0;
      in.get(c);
      if(*(object.pSize) == 0)
      {
          while(c != '\n')
          {
              object.content.push_back(c);
              in.get(c);  
              ++i;
          }
          *(object.pSize) = (int)object.content.size();
          *(object.pPosOfEnd) = object.content.end();
          *object.indexOfLastChar = i;
      }
      else
      {
          i = 0;
          std::vector&lt;char&gt;::const_iterator it = object.content.begin();
          while(c != '\n')
          {
              if(i == *object.pSize)
              {
                  *object.pPosOfEnd = it;
                  *object.indexOfLastChar = i;
              }
              if(i &gt;= *object.pSize)
              {
                  in.get(c);
                  continue;
              }
              object.content.push_back(c);
              in.get(c);
              ++i;
          }
      }
  
  
      *(object.pPos) = object.content.begin();
  </code></pre>
  
  <p>And thats it :)</p>
  
  <p>Aaaaand although I'm sorry to show this to the world, here's my ugly Interface class method. All of my program input/output is managed through Interface.writeOutput method, which is here:</p>
  
  <pre><code>Interface::Interface()
  {
      menu = new char*[12];
      menu[0] = "Welcome, please select an option from the following, by pressing the respective numbers:";
      menu[1] = "1  Create a Directory\n2  Create a single File\n3  Exit program";
      menu[2] = "Ok, now please select a further option:";
      menu[3] = "Enter the number of Files you want to import: ";
      menu[4] = "Enter the files...";
      menu[5] = "1  Write out the Directory details\n2  Extract N bytes from a desired file\n3  Remove a file with desired name from the Directory\n4  Write content of a file\n0  Go back to the beginning";
      menu[6] = "Enter the index of the file: ";
      menu[7] = "Enter how many bytes to extract: ";
      menu[8] = "Content of the extracted bytes: ";
      menu[9] = "Enter the name of the file: ";
      menu[10] = "What do you want to do next?";
      menu[11] = "Please enter a regular number...";
  }
  
  
  void Interface::writeMenu()
  {
      Error e;
      char c, tmp[5], name[30];
      int n, k, index, i, numDir;
      char *buffer; 
      int *haveReadFiles;
  
      std::cout&lt;&lt;menu[0];
      std::cout&lt;&lt;"\n\n";
  startMenu: 
      std::cout&lt;&lt;menu[1];
      std::cout&lt;&lt;"\n\n";
      std::cin&gt;&gt;c;
      if((!isdigit(c)) || ( c != '1' &amp;&amp; c!= '2' &amp;&amp; c!='3'))
      {
          std::cout&lt;&lt;"\n"&lt;&lt;menu[11]&lt;&lt;"\n\n";
          goto startMenu;
      }
      if(c == '1')
      {
          std::cout&lt;&lt;"Enter the name of the directory: ";
          std::cin&gt;&gt;name;
          Directory d(name);
          std::cout&lt;&lt;"\n\n\nEnter number of files of directory: ";
          std::cin&gt;&gt;numDir;
          haveReadFiles = new int[numDir];
          if(!haveReadFiles)
          {
              e.writeToOutput(7);
              exit(1);
          }
  
          for(i = 0; i &lt; numDir; i++)
          {
          haveReadFiles[i] = 0;   
              //std::cin.ignore(5,'\n');
          //  std::cin.ignore ( std::numeric_limits&lt;std::streamsize&gt;::max(), '\n' );
              File f;
              std::cin&gt;&gt;f;
              d += f;
          }
  
      menu1:
          std::cout&lt;&lt;"\n\n"&lt;&lt;menu[2]&lt;&lt;"\n\n";
  menuRepeat:
          std::cout&lt;&lt;menu[5];
          std::cout&lt;&lt;"\n\n";
          std::cin&gt;&gt;c;
          if(!isdigit(c) || (c != '1' &amp;&amp; c!= '2' &amp;&amp; c!='3' &amp;&amp; c != '4' &amp;&amp; c != '0'))
          {
              std::cout&lt;&lt;"\n"&lt;&lt;menu[11];
              goto menu1;
          }
          switch(c)
          {
          case '0': goto startMenu;break;
          case '1': std::cout&lt;&lt;d;break;
          case '2': 
              {
                  menu2:
                  std::cout&lt;&lt;"\n\n"&lt;&lt;menu[6];
  
                  std::cin&gt;&gt;tmp;
                  for(i = 0; i &lt; (int)strlen(tmp); i++)
                      if(!isdigit(tmp[i]))
                      {
                          std::cout&lt;&lt;"\n\n"&lt;&lt;menu[11];
                          goto menu2;
                      }
                  index = atoi(tmp);
                  menu3:
                  std::cout&lt;&lt;"\n\n"&lt;&lt;menu[7];
                  std::cin&gt;&gt;tmp;
                  for(i = 0; i &lt; (int)strlen(tmp); i++)
                      if(!isdigit(tmp[i]))
                      {
                          std::cout&lt;&lt;"\n\n"&lt;&lt;menu[11];
                          goto menu3;     
                      }
                  n = atoi(tmp);
  
  
                  buffer = new char[n+1];
                  k = d[index](buffer, n);
                  std::cout&lt;&lt;"Extracting of "&lt;&lt;k&lt;&lt;" bytes succeeded, and here is the content extracted:\n";
                  std::cout&lt;&lt;"\""&lt;&lt;buffer&lt;&lt;"\"";
              } break;
          case '3':
              {
                  std::cout&lt;&lt;"\n\nEnter the name of the file: ";
                  std::cin&gt;&gt;name;
                  d -= name;
                  std::cout&lt;&lt;"...file removed!\n";
                  std::cout&lt;&lt;"Directory without the removed file looks like this: \n\n"&lt;&lt;d;
              }break;
          case '4': 
              {
                  menuFF:
                  std::cout&lt;&lt;"\n\nEnter the index of the desired file: ";
                  std::cin&gt;&gt;tmp;
                  for(i = 0; i &lt; (int)strlen(tmp); i++)
                      if(!isdigit(tmp[i]))
                      {
                          std::cout&lt;&lt;"\n\n"&lt;&lt;menu[11];
                          goto menuFF;
                      }
                  index = atoi(tmp);
                  std::cout&lt;&lt;"\nHere's the content:\n";
                  File ff = d[index];
                  std::vector&lt;char&gt;::const_iterator iter = ff.content.begin();
                  for(; iter &lt; ff.content.end(); ++iter)
                  {
                      std::cout&lt;&lt;*iter;
                  }
                  std::cout&lt;&lt;"\n\n";
              }
          }
          menu4:
          std::cout&lt;&lt;"\n\nWhat do you want to do now?\n\n1  Exit program\n2  Go back to start menu\n3  Do more stuff with your Directory\n\n";
          std::cin&gt;&gt;c;
          if((!isdigit(c)) || ( c != '1' &amp;&amp; c!= '2' &amp;&amp; c!='3'))
          {
              std::cout&lt;&lt;"\n"&lt;&lt;menu[11];
              goto menu4;
          }
          if(c=='1')
          {
              "Thank you, goodbye...";
              exit(0);
          }
          if(c=='2')
              goto startMenu;
          if(c=='3')
              goto menuRepeat;
      }
      else if(c=='2')
      {
          std::cout&lt;&lt;"Enter your file...\n";
          File g;
          std::cin&gt;&gt;g;
          menuZZ:
          std::cout&lt;&lt;"\n\nHere's what you can do with your file: \n\n1  Extract N bytes of content from it\n2  Write its content out\n3  Write its properties out\n4  Return to start menu\n\n";
          std::cin&gt;&gt;c;
          switch(c)
          {
          case '1':
              {
  
                  menuYY:
                  std::cout&lt;&lt;"\n\n"&lt;&lt;menu[7];
                  std::cin&gt;&gt;tmp;
                  for(i = 0; i &lt; (int)strlen(tmp); i++)
                      if(!isdigit(tmp[i]))
                      {
                          std::cout&lt;&lt;"\n\n"&lt;&lt;menu[11];
                          goto menuYY;        
                      }
                  n = atoi(tmp);
                  buffer = new char[n+1];
                  k = g(buffer, n);
                  std::cout&lt;&lt;"Extracting of "&lt;&lt;k&lt;&lt;" bytes succeeded, and here is the content extracted:\n";
                  std::cout&lt;&lt;"\""&lt;&lt;buffer&lt;&lt;"\"";
                  std::cout&lt;&lt;"\n\n";
                  goto startMenu;
              } break;
          case'2':
              {
                  std::vector&lt;char&gt;::const_iterator it = g.content.begin();
                  for(; it &lt; g.content.end(); ++it)
                  {
                      std::cout&lt;&lt;*it;
                  }
                  std::cout&lt;&lt;"\n\n";
              }
          case'3':
              {
                  std::cout&lt;&lt;g&lt;&lt;"\n\n";
                  goto startMenu;
              } break;
          case'4': 
              {
                  std::cout&lt;&lt;"\n\n";
                  goto startMenu;
              } break;
          default:
              {
                  std::cout&lt;&lt;menu[11];
                  goto menuZZ;    
              }
  
          }
      }
      else
      {
          std::cout&lt;&lt;"Thank you, goodbye... ";
          exit(0);
      }
  }
  </code></pre>
  
  <p>Edit 2: </p>
  
  <p>Last but not least, the <code>Directory::operator [] implementation</code>:</p>
  
  <p>In header: <code>File&amp; operator [] (int);</code></p>
  
  <p>Implementation: </p>
  
  <pre><code> File&amp; Directory::operator [] (int index)
  {
      std::vector&lt;File&gt;::const_iterator i = arr.begin();
      for(int j = 0; j &lt; index; ++j)
          ++i;
      File* temp = new File;
      *temp = *i;
      return *temp;
      delete temp;
  }
  </code></pre>
  
  <p>enjoy ^^</p>