devxlogo

Tip Bank

How Do I Christen This Class?

Good design goes hand in hand with the nomenclature it uses for exchanging that design between developers. A key feature to writing good code consists of good naming conventions and

Checking Whether a Stack Is Empty

It is an error to call the member function pop() on an empty stack. If you are not sure whether a stack contains any elements, you can use the member

Always Initialize Pointers

An uninitialized pointer has an indeterminate value. It’s almost impossible to test subsequently whether such a pointer is valid, especially if it is passed as an argument to a function,

Simplify Creating and Adding Menu Items

When creating menu items and adding them to a menu, you can shorten your code by combining two steps into one. Instead of creating the menu item and adding it

Data Pointers vs. Function Pointers

C and C++ make a clear-cut distinction between two types of pointers: data pointers and function pointers. A function pointer embodies several constituents such as the list of arguments, a

When to Use a Pure Virtual Member Function

A pure virtual function is merely an interface and can be thought of as a way to enforce policy. A pure virtual function should be used when subclasses implement the

Integer Affixes

You can use affixes to help the compiler figure out the correct type of a hard coded integer. The letter L affixed to a number indicates a long integer and

Elaborated Type Specifier

An elaborated type specifier is a type name preceded by one of the keywords: enum, struct, union, and class. You can use an elaborated type specifier to instantiate an object

Using bsearch the Right Way

Standard C defines the function bsearch, which performs a binary search on an array of elements. The function bsearch is very efficient, but it works only on sorted arrays. You