Sharing a Worker Object

Suppose that we have the example program in Figure 10.33 (which is contained in the file refcnt1.cpp if you want to print it out).

Figure 10.33. Safe polymorphism: An example program for reference-counting with StockItems (code\refcnt1.cpp)
#include <iostream>
#include <string>
#include "itemp.h"
using namespace std;
int main()
   StockItem item1("cups",32,129,10,5,"Bob's Dist.",
     "2895657951"); // create an undated object

   StockItem item2("Hot Chicken",48,158,15,12,"Joe's Dist.",
     "987654321", "19960824"); // create a dated object

    StockItem item3 = item1; // copy constructor
    item1 = item2; // assignment operator

    item1.FormattedDisplay(cout); // display an object with labels

    return 0;

This program doesn't do anything ...

Get C++: A Dialog Programming with the C++ Standard Library now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.