title: C++ MyInteger Class with Overload [ ] operator so index returns digit in position i
body: <p><strong>The problem I have</strong></p>
  
  <p>Define a class named MyInteger that stores an integer and has functions to get and set the intergers value. Then, overload the [] operator so that the index returns the digit in position i, where i = 0 is the least-significant digit. If no such digit exists then -1 should be returned.</p>
  
  <p>I understand the first part but I don't understand how to implement the second part, </p>
  
  <blockquote>
    <p>Then, overload the [] operator so that the index returns the digit in position i, where i = 0 is the least-significant digit. If no such digit exists then -1 should be returned.</p>
  </blockquote>
  
  <p><strong>My code is such:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class MyInteger{
  private:
    int integer;
  public:
    MyInteger(int bInteger = 0)
    {
       integer = bInteger;
    }
    int getInteger(){ return integer; }
    void setInteger(int bInteger){ integer = bInteger; }
  
    void operator[](int x) //???
    {
    }
  
  };
  
  int main()
  {
  
    cout &lt;&lt; "Enter an integer " &lt;&lt; endl;
    //cin &gt;&gt; 
  
  }
  </code></pre>