Reliable Software Logo

C++ In Action: Language


Objects of any type (built-in, derived, or user defined) can be defined within the global scope or local scopes. Bodies of functions (such as main()) and member functions form local scopes. Within a given local scope one can create sub-scopes which can have sub-sub-scopes, and so on. A sub-scope is usually delimited by braces, but in certain constructs, such as the for loop, or the conditional if/else (we'll see examples later) a single-statement body may be braceless and yet it will form a sub-scope.

A class is a user-defined type. Class behavior is specified by the interface--the set of member functions (including constructors and a destructor) together with the description of their behavior. A member function takes zero or more arguments and returns a value (which can be empty--the void return type). The implementation of the class is specified by the bodies of member functions and the types of data members. The implementation fulfills the contract declared by the interface.

Objects can be combined by embedding and inheritance--semantically corresponding to the has-a and is-a relationships. Embedding and inheritance may be combined in various way leading to objects containing objects that inherit from other objects, that inherit from yet other objects, that contain..., etc.

NextNext: Word of Caution