Research Paper
Research Paper
ABSTRACT
This overview of C++ presents the key design, programming, and language-technical concepts
using examples to give the reader a feel for the language. C++ is a general-purpose
programming language with a bias towards systems programming that supports efficient low-
level computation, data abstraction, object-oriented programming, and generic programming.
This paper is organized around the main programming styles directly supported by C++:
The Design and Evolution of C++ describes the aims of C++ and the principles that
guided its evolution.
The C Programming Model presents the C subset of C++and other C++facilities
supporting traditional systems-programming styles.
The C++ Abstraction Mechanisms introduces C ++ ’s class concept and its use for
defining new types that can be used exactly as built-in types, shows how abstract classes
can be used to provide inter-faces to objects of a variety of types, describes the use of
class hierarchies in object-oriented programming, and presents templates in support of
generic programming.
Large-Scale Programming describes namespaces and exception handling provided to ease
the composition of programs out of separate parts.
The C++Standard Library presents standard facilities such as I/O streams, strings,
containers (e.g. Vector, list and map), generic algorithms (e.g. s sort(), find(), for_
each()) and support for numeric computation.
To round off, a brief overview of some of the tasks that C++has been used for and some
suggestions for further reading are given
The subscript notation [] is used both in declarations to indicate an array and in expressions
referring to elements of an array.
A C pointer is a variable that can hold an address of a memory location. For example:
The pointer dereference (‘‘points to’’) notation * is used both in declarations to indicate a pointer
and in expressions referring to the element pointed to. adopted this inherently simple and close-
to-the-machine notion of memory from C. It also adopted C’s notion of expressions, control
structures, and functions. For example, we can write a function that finds an element in a vector
and returns a pointer to the matching element like this:
int* find (int v[] , int vsize , int Val) / / find Val in v
{
for (int i = 0 ; i<vsize; i++) / / loop through 0..vsize-1
if (v [i]==Val) return &v [i] ; / / if Val is found return pointer to element
return &v [vsize] ; / / if not found return pointer to one-beyond-the-end of v
}
The ++ operator means increment. Thus, the name C++ can be read as ‘‘one more than C,’’
‘‘next C,’’ or ‘‘successor to C.’’ It is pronounced ‘‘See Plus Plus.’’ The find() function might be
used like this:
Int count[ ] = { 2, 3, 1, 9, 7, 3, 3, 0, 2 };
Int count _size= 9;
void f ( )
{
int* p= find (count, count_size,7) ; / / find 7 in count
int* q= find (count, count_size,0) ; / / find 0 in count
*q = 4;
}
The C++ standard library provides more general versions of functions such as find( );
A function declared void, as f ( ) above doesn’t return a value.
Abstraction
In addition to convenient and efficient mechanisms for expressing computation and allocating
objects, we need facilities to manage the complexity of our programs. That is, we need language
mechanisms for creating types that are more appropriate to the way we think (to our application
domains) than are the low-level built-in features.
Object-Oriented Programming
Object-oriented programming is a set of techniques that rely on hierarchies of classes to provide
extensibility and flexibility. The basic language facilities used are the user-defined types
themselves, the ability to derive a class from another, and virtual functions. These features allow
a programmer to rely on an interface (a class, often an abstract class) without knowing how its
operations are implemented. Conversely, they allow new classes to be built directly on older
ones without disturbing users of those older classes. As an example, consider the simple task of
getting an integer value from a user to an application
through some user-interface system. Assuming that we would like to keep the application
independent of the details of the user-interface system we could represent the notion of an
interaction needed to get an integer as a class IVal _box:
Generic Programming
Given classes and class hierarchies, we can elegantly and efficiently represent individual
concepts and also represent concepts that relate to each other in a hierarchical manner. However,
some common and important concepts are neither independent of each other nor hierarchically
organized. For example, the notions ‘‘vector of integer’’ and ‘‘vector of complex number’’ are
related through the common concept of a vector and differ in the type of the vector elements
(only). Such abstractions are best represented through parameterization. For example, the vector
should be parameterized by the element type. C++ provides parameterization by type through the
notion of a template. It was a crucial design criterion that templates should be flexible and
efficient enough to be used to define fundamental containers with severe efficiently constraints.
In particular, the aim was to be able to provide a vector template class that did not impose run-
time or space overheads compared to a built-in array.
References
[Barton,1994] John J. Barton and Lee R. Nackman: Scientific and Engineering C++. Addison-
Wesley. Reading, Mass. 1994. ISBN 1-201-53393-6.
[Berg,1995] William Berg, Marshall Cline, and Mike Girou: Lessons Learned from the OS/400
OO Project. CACM. Vol. 38 No. 10. October 1995.
[Stepanov,1994] Alexander Stepanov and Meng Lee: The Standard Template Library. HP Labs
Technical Report HPL-94-34 (R. 1). August, 1994