Passing std::ostream to function?
<p>I'm working through the example programs of <em>Wiley's Teach Yourself C++</em> (7th Edition) using LLVM clang++ (version 3.1 on FreeBSD) as my compiler. In Ch. 23, "Class Inheritance", the following code is provided:</p>

<p>Date.h - the base class:</p>

<pre><code>...snip..
inline void Date::Display(std::ostream&amp; os)
   { os &lt;&lt; "Date: " &lt;&lt; *this; }
...snip...
</code></pre>

<p>SpecialDate.h - the class derived from Date and overloads the Display() function:</p>

<pre><code>#include "Date.h"
...snip...
void Display(std::ostream&amp; os)
   { os &lt;&lt; "SpecialDate: " &lt;&lt; *this; }
...snip...
</code></pre>

<p>23-1.cpp - instantiates an object of SpecialDate and uses it:</p>

<pre><code>#include &lt;iostream&gt;
#include "SpecialDate.h"
int main()
{
...snip... 
// da, mo, &amp; yr are all ints and declared
SpecialDate dt(da, mo, yr);
...snip...
dt.Display();
...snip...
</code></pre>

<p>When I compile the code, the only error I get is:</p>

<pre><code>./23-1.cpp:14:14: error: too few arguments to function call, expected 1, have 0
            dt.Display();
            ~~~~~~~~~~ ^
./SpecialDate.h:15:2: note: 'Display' declared here
    void Display(std::ostream&amp; os)
    ^
1 error generated.
</code></pre>

<p>I can see that I need to pass by reference a std::ostream type variable to Display(), but I'm stumped on how to proceed.  FWIW: both Date.h and SpecialDate.h overload the <code>&lt;&lt;</code> operator. I've tried:</p>

<pre><code>dt.Display(std::cout); /* all sorts of weird compiler errors */
...
std::ostream os; /* error: calling a protected constructor of class */
dt.Display(os);
...
std::cout &lt;&lt; dt.Display(); /* same "too few arguments" error */
</code></pre>

<p>What do I need to do to get this code to compile?</p>

<p>EDIT:
Chris, clang++ errors for <code>dt.Display(std::cout);</code>:</p>

<pre><code>/tmp/23-1-IecGtZ.o: In function `SpecialDate::Display(std::ostream&amp;)':
./23-1.cpp:(.text._ZN11SpecialDate7DisplayERSo[_ZN11SpecialDate7DisplayERSo]+0x34):    undefined reference to `operator&lt;&lt;(std::ostream&amp;, SpecialDate&amp;)'
/tmp/23-1-IecGtZ.o: In function `Date::Date(int, int, int)':
./23-1.cpp:(.text._ZN4DateC2Eiii[_ZN4DateC2Eiii]+0x34): undefined reference to `Date::SetDate(int, int, int)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
</code></pre>

<p>Also, <code>#include &lt;iostream&gt;</code> is in both Date.h and SpecialDate.h.</p>

<p>EDIT 2: After re-reading the errors for <code>dt.Display(std::cout);</code>, I realized that the compiler was not seeing the source for SpecialDate and Date, just the headers. So I added those to the command line and it finally compiled without errors!</p>

<pre><code>clang++ 23-1.cpp Date.cpp SpecialDate.cpp
</code></pre>

<p>Unfortunately, the behavior is not as expected (the date is not being displayed), but my original question has been answered. I'll continue to poke at it. Thanks for your patience with a noob!</p>
