Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you are asking is nothing but operator overloading. <code>c1 and c2</code> are objects of <code>Class1</code>. Here <code>Extraction operator(&gt;&gt;) and + operator</code> has been overloaded. </p> <p>Check this out:-</p> <p><a href="http://www.cprogramming.com/tutorial/operator_overloading.html" rel="nofollow">Operator Overloading in C++</a></p> <p>Example of a class overloading >> and &lt;&lt; operator:- </p> <pre><code>#include &lt;iostream&gt; using namespace std; class Distance { private: int feet; // 0 to infinite int inches; // 0 to 12 public: // required constructors Distance(){ feet = 0; inches = 0; } Distance(int f, int i){ feet = f; inches = i; } friend ostream &amp;operator&lt;&lt;( ostream &amp;output, const Distance &amp;D ) { output &lt;&lt; "F : " &lt;&lt; D.feet &lt;&lt; " I : " &lt;&lt; D.inches; return output; } friend istream &amp;operator&gt;&gt;( istream &amp;input, Distance &amp;D ) { input &gt;&gt; D.feet &gt;&gt; D.inches; return input; } }; int main() { Distance D1(11, 10), D2(5, 11), D3; cout &lt;&lt; "Enter the value of object : " &lt;&lt; endl; cin &gt;&gt; D3; cout &lt;&lt; "First Distance : " &lt;&lt; D1 &lt;&lt; endl; cout &lt;&lt; "Second Distance :" &lt;&lt; D2 &lt;&lt; endl; cout &lt;&lt; "Third Distance :" &lt;&lt; D3 &lt;&lt; endl; return 0; } </code></pre> <p>Source:- <a href="http://www.tutorialspoint.com/cplusplus/input_output_operators_overloading.htm" rel="nofollow">http://www.tutorialspoint.com/cplusplus/input_output_operators_overloading.htm</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload