Sending result of overloaded + member function to overloaded << leads to compile error
<p>I am working on creating a class to handle very large numbers for use in project euler challenges.  I have overloaded both &lt;&lt; and + to work with the class.  The following compiles and works properly:</p>

<pre><code>BigNum a(400000000);
BigNum b(400000000);
BigNum c;

c = a + b;

cout &lt;&lt; c; 
</code></pre>

<p>The following produces a compile error:</p>

<pre><code>BigNum a(400000000);
BigNum b(400000000);

cout &lt;&lt; (a + b); 
</code></pre>

<p>The error is:   error: no match for 'operator&lt;&lt;' in 'std::cout &lt;&lt; BigNum::operator+(const BigNum&amp;) const(((const BigNum&amp;)((const BigNum*)(&amp; b))))'</p>

<p>For reference, here is the class definition and implementation:  </p>

<pre><code>/* BigNum.h */

#include &lt;iostream&gt;
#include &lt;vector&gt;

class BigNum {
public: 
BigNum();
BigNum(const BigNum &amp;src);
BigNum(int num);
void print(std::ostream *os);

public:
BigNum &amp;operator=(const BigNum &amp;src);
BigNum &amp;operator+=(const BigNum &amp;src);
const BigNum operator+(const BigNum &amp;src) const;

private:
bool negative;
std::vector&lt;int&gt; digits;
};

std::ostream &amp;operator&lt;&lt;(std::ostream &amp;os, BigNum &amp;bNum);

/* BigNum.cpp */

#include "BigNum.h"

BigNum::BigNum() {
digits.push_back(0);
}

BigNum::BigNum(const BigNum &amp;src) {
digits = src.digits;
}

BigNum::BigNum(int num) {
if(num == 0) {
    digits.push_back(0);
}
else {
    while(num != 0) {
        digits.push_back(num % 10);
        num /= 10;
    }
}
}

void BigNum::print(std::ostream *os) {
int i;

for(i = digits.size() - 1; i &gt;= 0; i--) {
    *os &lt;&lt; digits[i];
}
}

std::ostream &amp;operator&lt;&lt;(std::ostream &amp;os, BigNum &amp;bNum) {
bNum.print(&amp;os);
return os;
}

BigNum &amp; BigNum::operator=(const BigNum &amp;src) {
if(this == &amp;src) return *this;

digits = src.digits;

return *this;
}

BigNum &amp; BigNum::operator+=(const BigNum &amp;src) {
int carry, i, k;

carry = 0;

if(digits.size() &lt; src.digits.size()) {
    digits.resize(src.digits.size(), 0);
}

{
    k = src.digits.size();
    for(i = 0; i &lt; k; i++) {
        digits[i] += src.digits[i]; 
        digits[i] += carry;
        carry = 0;
        if(digits[i] &gt; 9) {
            carry = 1;
            digits[i] -= 10;
        }
    }

    k = digits.size();
    for(i = src.digits.size(); i &lt; k; i++) {
        digits[i] += carry;
        carry = 0;
        if(digits[i] &gt; 9) {
            carry = 1;
            digits[i] -= 10;
        }
    }

    if(carry) {
        digits.resize(digits.size() + 1, 1);
    }
}

return *this;
}

const BigNum BigNum::operator+(const BigNum &amp;src) const {
BigNum result(*this);
result += src;
return result;
}
</code></pre>

<p>Why does </p>

<pre><code>cout &lt;&lt; (a + b);
</code></pre>

<p>not work?  There are obvious work-arounds, but I want to understand why this is happening.  I am new to C++, so if there is anything else I am doing incorrectly or could be doing better, please let me know.  Thank you.  </p>
