March 6, 2001

Warnings Regarding Temporaries and Their Meaning

The following code causes a somewhat cryptic warning message: struct Employee{ long ID; string name;};Employee emp;void func(int& id) { id=0;}// warning below issued for the following call:func(emp.ID);

Right-Justification of Output

To right justify the output of cout, call the width() function with the size of the output screen (in characters) as an argument. In the following example, the program calls

What You Should Include in a Header File

A header file should begin and end with #include guards to guarantee that it’s not #included more than once during the same compilation session. A typical #include guard looks as

Enumerate Collections With For Each…Next

It’s faster to enumerate a collection with the For each…Next statetment: Dim c As Class1 For Each c In Col ‘Code… NextDim fldField As ADODB.Field For Each fldField In rsTemp

Alternatives to ios::nocreate and ios::noreplace

In pre-standard C++, certain implementations of offered the flags ios::nocreate and ios::noreplace for controlling file creation. These flags were too platform-specific and never made it into the standard library, which

Standard Exit Codes

C++ defines the symbolic constants EXIT_SUCCESS and EXIT_FAILURE that you can use as return codes. These macros are defined in the header file ( in C) as follows: #define EXIT_SUCCESS

Deleting Elements of a Container of Pointers

This is a common source of misunderstanding: a programmer creates a container of pointers, then fills that container with pointers to dynamically allocated objects. When the container is destroyed, the

Arrays of Pointers to Members

You can create an array of pointers to member just as you would create arrays of any other type. The following example creates an array of pointers to member functions