Garbage values from third class object C++
<p>Here is a snippet of the implementation file for the stock source:</p>

<pre><code> stock::stock(char const * const symbol, char const * const name, int sharePrice, date priceDate )
 : m_sharePrice( sharePrice )
 {
    if ( symbol )
    {
        size_t length = strlen( symbol ) +1;
        m_symbol = new char[length];
        strcpy_s( m_symbol, length, symbol );
    }
    else m_symbol = NULL;
    if ( name )
    {
            size_t length = strlen( name ) +1;
       m_name = new char[length];
       strcpy_s( m_name, length, name );
    }
    else m_name = NULL;

    dateObj = &amp;priceDate;
 }
</code></pre>

<p>This is just what I do to allocate memory with cstrings. In main the paramaters are passed in like, "symbol, "name", 10, date::JANUARY, 17, 1967. The date is an object where its months are enumaterted. It is this last paramater "date" type is what iim having trouble with. Im having trouble keeping the attributes when moving from one source file to the next. I see that in the function above, "dateObj" has the attributes that I need.  But when I go to transfer it in another source file the values are gone...</p>

<pre><code>pragma once
#include &lt;ostream&gt;
using namespace std;

class date
  {
  public:
    typedef enum {INVALID, JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE,
              JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER,DECEMBER}
    Month;

    date(Month month, int day, int year);
    date(const date&amp; date);         // copy constructor
    date(void);                              // default constructor
    ~date(void);

    friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const date&amp; d);

 private:
    Month   month;
    int     day;
    int     year;
};
</code></pre>

<p>So when I need to add to the hashTable, or visa versa, I end up with garable values.</p>

<pre><code>bool hashmap::get(char const * const symbol, stock&amp; s) const
{
    int index = 0;
    // search for the stock associated with the symbol.
    while ( index &lt; maxSize )
    {
        if ( hashTable[index].m_symbol == NULL ) 
        {
            index++;
        }
        else if ( strcmp( symbol, hashTable[index].m_symbol  ) == 0 )
        {
        //s = *hashTable; // call assignemnt overload
             s.m_name = hashTable[index].m_name; // has correct value
             s.dateObj = hashTable[index].dateObj; // GARBLE!
             s.m_sharePrice = hashTable[index].m_sharePrice; // correct 
             s.m_symbol = hashTable[index].m_symbol; // correct
             return true;
        }
    }
        return false;
    }
</code></pre>

<p>Maybe if i could add something to one of the header files to make this easier.</p>

<pre><code> #include "date.h"

 using namespace std;

 class stock
 {
  public:
    stock(char const * const symbol, char const * const name, int sharePrice, date priceDate);
    stock(const stock&amp; s);  // copy constructor
    stock(void);                                     // default constructor
    char const * const getSymbol(void) const;
    stock&amp; operator=(const stock&amp; s);
    stock&amp; operator=(stock const * const s);
    ~stock(void);

    // display column headers
    static void displayHeaders(ostream&amp; out);

     friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const stock&amp; s);

     friend class hashmap;
     private:

     date *dateObj;
     char *m_symbol;
     char *m_name;
     int   m_sharePrice;

     static int   maxSize;
  };

 #include "stock.h"

 class hashmap
 {
  public:
hashmap(int capacity);
~hashmap(void);
bool get(char const * const symbol, stock&amp; s) const;

    bool put(const stock&amp; s, int&amp; usedIndex, int&amp; hashIndex, int&amp; symbolHash);
    bool remove(char const * const symbol);

    friend ostream&amp; operator&lt;&lt;(ostream&amp; out, const hashmap&amp; h);

private:
        static int hashStr(char const * const symbol);
    friend class stock;

    stock *hashTable;
 };
</code></pre>

<p>This might be where I can solve the problem of the date attributes not keeping their values. IM just not sure where to do what.</p>

<pre><code> #include "date.h"

 date::date(Month month, int day, int year)
 {
    this-&gt;month = month;
    this-&gt;day  = day;
    this-&gt;year = year;
 }

date::date(const date&amp; date)
{
}

date::date()
{
    day = this-&gt;day;
    year = this-&gt;year;  
        month = this-&gt;month;
}

date::~date(void)
{

}

ostream&amp; operator&lt;&lt;(ostream&amp; out, const date&amp; d)
{
   out &lt;&lt; d.day &lt;&lt; d.month &lt;&lt; d.year &lt;&lt; endl;
        return out;
}
</code></pre>
