next up previous contents
Next: Object-Oriented Programming Up: The C++ Programming Language Previous: Features Borrowed from Other

C++ Versus C

To demonstrate the distinctions between C and C++, numerous features supported by C++ which have no equivalent in C are provided below. Some of these features will be discussed in more detail in the section on object-oriented programming.

When a user defines a type in C++, support is provided in the language to permit that type to behave in a manner similar to types already built into the language. The user may define how the standard operators act upon these user defined types (operator overloading) and how these type can be converted to another type (user defined conversions). The user may also specify how memory is allocated or deallocated when an instance of that type is created or destroyed. This is done through the use of constructors and destructors which are called implicitly by the compiler when an instance of that type is brought into and taken out of scope respectively.

C++ provides support for function prototypes, hence enabling strong type checking of function parameters to take place during compilation. In addition, C++ provides support for the pass by reference mechanism and also supports default arguments to functions. This means that should a function require an argument that often has the same value, the user can default the argument to that value and not pass that parameter when the function is called. In the few cases where the function has to be called with a different value for the default argument, the user simply passes that argument into the function and the new value overrides the default value.

The most important features which C++ provides support for are data encapsulation, inheritance and runtime binding which form the foundation for the language's support for object-oriented programming. These features are discussed in detail in the next section.

Donald Craig
Sat Jul 13 16:02:11 NDT 1996