The keyword const can be used to specify that an object is not modifiable and that any attempt to modify the object should result in a compilation error.
C++ compilers disallow non-const member function calls on const objects.
An attempt by a const member function to modify an object of its class (*this) is a compilation error.
A function is specified as const both in its prototype and in its definition.
A const object must be initialized, not assigned to.
Constructors and destructors cannot be declared const.
const data member and data members that are references must be initialized using member initializers.
A class can have objects of other classes as membersthis concept is called composition.
Member objects are constructed in the order in which they are declared in the class definition and before their enclosing class objects are constructed.
If a member initializer is not provided for a member object, the member object's default constructor will be called implicitly.
A friend function of a class is defined outside that class's scope, yet has the right to access the non-public (and public) members of the class. Stand-alone functions or entire classes may be declared to be friends of another class.
A friend declaration can appear anywhere in the class. A friend is essentially a part of the public interface of the class.
The friendship relation is neither symmetric nor transitive.
Every object has access to its own address through the this pointer.
An object's this pointer is not part of the object itselfi.e., the size of the memory occupied by the this pointer is not reflected in the result of a sizeof operation on the object.
The this pointer is passed (by the compiler) as an implicit argument to each of the object's non-static member functions.
Objects use the this pointer implicitly (as we have done to this point) or explicitly to reference their data members and member functions.
The this pointer enables cascaded member-function calls in which multiple functions are invoked in the same statement.
Dynamic memory management enables programmers to control the allocation and deallocation of memory in a program for any built-in or user-defined type.
The free store (sometimes called the heap) is a region of memory assigned to each program for storing objects dynamically allocated at execution time.
The new operator allocates storage of the proper size for an object, runs the object's constructor and returns a pointer of the correct type. The new operator can be used to dynamically allocate any fundamental type (such as int or double) or class type. If new is unable to find space in memory for the object, it indicates that an error occurred by "throwing" an "exception." This usually causes the program to terminate immediately.
To destroy a dynamically allocated object and free the space for the object, use the delete operator.
An array of objects can be allocated dynamically with new as in
int *ptr = new int[ 100 ];
which allocates an array of 100 integers and assigns the starting location of the array to ptr. The preceding array of integers is deleted with the statement
A static data member represents "class-wide" information (i.e., a property of the class shared by all instances, not a property of a specific object of the class).
static data members have class scope and can be declared public, private or protected.
A class's static members exist even when no objects of that class exist.
To access a public static class member when no objects of the class exist, simply prefix the class name and the binary scope resolution operator (::) to the name of the data member.
A class's public static class members can be accessed through any object of that class.
A member function should be declared static if it does not access non-static data members or non-static member functions of the class. Unlike non-static member functions, a static member function does not have a this pointer, because static data members and static member functions exist independently of any objects of a class.
Abstract data types are ways of representing real-world and conceptual notions to some satisfactory level of precision within a computer system.
An abstract data type captures two notions: a data representation and the operations that can be performed on those data.
C++ is an intentionally sparse language that provides programmers with only the raw capabilities needed to build a broad range of systems. C++ is designed to minimize performance burdens.
Items are returned from a queue in first-in, first-out (FIFO) orderthe first item inserted in the queue is the first item removed from the queue.
Container classes (also called collection classes) are designed to hold collections of objects. Container classes commonly provide services such as insertion, deletion, searching, sorting, and testing an item to determine whether it is a member of the collection.
It is common to associate iterators with container classes. An iterator is an object that "walks through" a collection, returning the next item (or performing some action on the next item).
Providing clients of your class with a proxy class that knows only the public interface to your class enables the clients to use your class's services without giving the clients access to your class's implementation details, such as its private data.
When a class definition uses only a pointer or reference to an object of another class, the class header file for that other class (which would ordinarily reveal the private data of that class) is not required to be included with #include. You can simply declare that other class as a data type with a forward class declaration before the type is used in the file.
The implementation file containing the member functions for a proxy class is the only file that includes the header file for the class whose private data we would like to hide.
The implementation file containing the member functions for the proxy class is provided to the client as a precompiled object code file along with the header file that includes the function prototypes of the services provided by the proxy class.