November 27, 2000

“Setter” and “Getter” Member Functions

Encapsulation is a fundamental principle in object orientation. Encapsulation restricts direct access to a data member of a class. Instead, users query the object itself in order to get or

Streams and Pointers

Look at the following program. It compiles correctly under every standard-conforming compiler. At first, this may seem surprising because seemingly, because it’s impossible delete an object which is not a

auto_ptr and Derived Objects

The auto_ptr class template respects polymorphism and destroys derived objects of base pointers properly. In the following program, an auto_ptr is actually bound to a B * pointer, where B

Qualified Calls

A function call such as the following: classname::funcname(); is a qualified call. Qualified disambiguate function names. They are needed, for instance, in a class that inherits from several base classes,

Accessing Static Class Members

Because static class members are not associated with a particular object of their class, you can access them even if you haven’t instantiated any object. In the following example, the

Emitting a Beep

The escape sequence ‘a’ is the ASCII code for a beep. To emit a beep from your program, output this escape sequence to the standard output. For example: const char

Copy Constructor’s Signatures

C++ defines four possible forms for a class’s copy constructor. For a class called X, a copy constructor can have one of the following forms: X(X&);X(const X&);X(volatile X&);X(const volatile X&);

Constructor Names

Technically speaking, constructors have no name. This may seem strange at first because you define a constructor for class X as X::X(). However, this construct is not the name of