Designed by [Bjarne Stroustrup], a Danish computer scientist, starting in 1979 at Bell Labs.
is a better C, is a direct descendant of C89
- supports data abstraction (C with Classes)
- adds keyword
class, also keeps
- A union is a class defined with the class-key
union; it holds at most one data member at a time
- supports access control (compare with
- Members of a class defined with the keyword
classare private by default.
- Members of a class defined with the keywords
unionare public by default. * constructors and destructors * initialization * Rule of three
- adds keyword
- supports Object-oriented programming without extensions
- to be continue…
- supports function overloading
calc integer sum: 1 + 2 = 3 calc float sum: 1.1 + 2.2 = 3.3
- supports generic programming through the use of templates
Template calc int sum: 1 + 2 = 3 Template calc double sum: 1.1 + 2.2 = 3.3 Template calc int sum: 1 + 2 = 3
- supports overloading of operators
Overloaded “&&” and “ ” operators lose their short-circuit evaluation property.
- extends the C89 standard library with C++ standard library
For compatibility with the C standard library, provides the 26 C headers:
C++ style head file, e.g.:
#include <cstdio>instead of
#include <cstdio>imports the symbol names in
std::namespace and possibly in Global namespace.
#include <stdio.h>imports the symbol names in Global namespace and possibly in
Sample for C++ style header:
- explicit cast operator (
static_cast, dynamic_cast, const_cast and reinterpret_cast)
bool, comparison operators returns bool, while C returns int.
reference, also keeps the
- similar to a pointer
- NO need to use a prefix
*to access the value
- CANNOT be made to refer to a different object after its initialization
- CANNOT be NULL
x = 10 y = 20 pointer swap: x = 20 y = 10 x = 10 y = 20 reference swap: x = 20 y = 10 x = 10 y = 20
- introduce new keyword