Home > Articles > Programming > C/C++

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

The First Document Type: A Memo

Listing 3 illustrates a memo document. The advent of email kind of killed off the memo, which is usually a message concerning some matter of importance such as an office party or a vacation J. The memo class is derived from AnyOldDocument and just inherits the member functions and data members of this base class.

Listing 3 Our Most Basic Document—the Memo

class MemoDocument : AnyOldDocument {
public:
  explicit MemoDocument(int Id, char* name, int docType);
  virtual ~MemoDocument();
};

MemoDocument::MemoDocument(int Id, char* name, int docType) 
: AnyOldDocument(Id, name, docType)
{
  printf ("Creating a Memo document for: %s\n", name);
}

MemoDocument::~MemoDocument() { }

Looking at Listing 3, you can see that the constructor for MemoDocument uses the constructor from the base class. If you run the code supplied with this article you can see that the program output is as shown in Listing 4.

Listing 4 Program Output

Invoking 3-parameter constructor for AnyOldDocument
Creating a Memo document for: Calling All Employees

Listing 4 shows that the base class constructor is automatically called once an instance of MemoDocument is created. This is pretty powerful! It means that most of the complexity attached to creating document instances can reside in the base class (including error handling, special cases, and so on). This helps to simplify the application code that actually uses the documents.

Let’s now create an expanded document type by using the third constructor in AnyOldDocument. To begin with, let’s create an invoice document.

  • + Share This
  • 🔖 Save To Your Account