devxlogo

Tip Bank

DevX - Software Development Resource

Static member function

A static member function in a class can access only other static members of a class or variables which are not members of its class. It can be invoked even

DevX - Software Development Resource

Retrieving actual object type in run-time

C++ supports Run-time Type Identification (RTTI), which enables detection of actual object type during program execution using the built-in typeid() operator. Here is an example: //file: classes.hclass base{ base(); virtual

DevX - Software Development Resource

Global objects construction and destruction

In object-oriented programming (OOP), global objects are considered harmful. Particularly in C++, there’s even more reason to think twice before using them: a global object construction occurs before a program’s

DevX - Software Development Resource

When is a mem-initializer required?

A const member or a reference member cannot be initialized within an object’s constructor. Instead, they must be initialized in the constructor’s member-initializer list. Conceptually, mem-initialization takes place before the

DevX - Software Development Resource

Uses of an anonymous union

Unions are used to minimize memory waste. For example, consider the following database-transaction class used to update a person’s data. The key can be either a unique ID number or