title: overloading the extraction operator >> in C++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4421706/operator-overloading">Operator overloading</a>  </p>
  </blockquote>
  
  
  
  <p>I have to code a clock program in which I could enter the hours, minutes and seconds while overloading the extraction operator. These are my codes:</p>
  
  <p>clockType.h</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  class clockType
  {
  public:
     clockType();
     void getTime();
     friend istream&amp; operator&gt;&gt;(istream&amp;, const clockType);
  private:
     int hr, min, sec;
  }
  </code></pre>
  
  <p>clockType.cpp</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include'clockType.h"
  using namespace std;
  
  clockType::clockType()
  {
      hr = 0;
      min = 0;
      sec = 0;
  }
  
  void clockType::getTime()
  {
      while(hr&gt;=24)
          hr = hr - 24;
      while(min&gt;=60)
          min = min - 60;
      while(sec&gt;=60)
          sec = sec - 60;
      cout&lt;&lt;setfill('0')
          &lt;&lt;setw(2)&lt;&lt;hr&lt;&lt;":"
          &lt;&lt;setw(2)&lt;&lt;min&lt;&lt;":"
          &lt;&lt;setw(2)&lt;&lt;sec&lt;&lt;endl;
   }
  
   istream&amp; operator&gt;&gt;(istream&amp; in, clockType cl)
   {
      in&gt;&gt;cl.hr&gt;&gt;cl.min&gt;&gt;cl.sec;
      return in;
   }
  </code></pre>
  
  <p>entryPoint.cpp</p>
  
  <pre><code> #include&lt;iostream&gt;
   #include'clockType.h'
  
   using namespace std;
  
   int main()
   {
     clockType clock;
     cout&lt;&lt;"Enter hr, min, sec";
     cin&gt;&gt;clock;
     clock.getTime();
     return 0;
   }
  </code></pre>
  
  <p>There is no error. My question is, as I enter the hr, min and sec, why does it output 00:00:00? Why doesn't the >> pass its values to the object clock?</p>