I got you. But I must not be clear on something here, or making myself clear. The initial code that got my dander up is in the DatedStockItem::Reorder function, not the UndatedStockItem::Reorder function. I think I understand this all pretty well so far, but let me walk through what I see happens on the application program's call to StockItem::Reorder()(which is the only one the programmer sees):(posted 6985 days ago)
1. The StockItem::Reorder function is called, which just executes the line m_worker->Reorder(os);. 2. In the case of the worker being a DatedStockItem, that would of course call DatedStockItem::Reorder(ostream& os). 3. this funtion checks the date and if the product is expired outputs the fact that a return needs to be done and then 4. explicitly calls the funtion StockItem::Reorder(os);. 5. That would lead us back to 1. above.
I don't see how to escape this, or how UndatedStockItem::Reorder is ever called when the m_worker points to a DatedStockItem. My understanding so far leads me to believe that the last line as in 4. above should have to call UndatedStockItem::Reorder, as the type of the worker ...wait a minute, something just occurred to me while writing this. What I didn't get before was that the StockItem that the code in StockItem::Reorder was going to look at was NOT the one that had this DatedStockItem as it's m_worker,(its manager) but rather this worker's internal StockItem variable that had been initialized by the constuctor that takes an int as it's argument. That constructor always makes a m_worker that points to nothing, a zero. Is that how the code m_worker->Reorder(os); now somehow gets us to the UndatedStockItem::Reorder function? This really still isn't clear. I do now see, however, that:
6. the code m_worker->Reorder(os); now calls that function for the base class part of the DatedStockItem, which was initialized by the goofy constructor as a zero, a pointer to nothing.
can you fill me in on 7 & 8, whatever it takes to get to the code for the UndatedStockItem::Reorder now? I'm a little further along, but still don't see it. The type of a pointer that points to nothing isn't obvious to me, and I'm not following how a null pointer gives us the Undated function we want.
[ Previous | Next ]