![](https://csdnimg.cn/release/download_crawler_static/10338432/bg10.jpg)
2 1 Getting Started
1.1.1 C++ is “Object-Oriented”
You may have heard that C++ is an “object-oriented” language and have wondered
what that means. What marks a language which is object-oriented out from one that
is not? Fundamentally, it is because the basic unit of the language is an object or
class—an entity which brings together related functionality and data. We will probe
the ideas behind objects and classes more deeply in Chap. 6.
Many books on C++ start by defining object-orientation more explicitly. If this
book were aimed at a computer science or software engineering audience, then we
would find it necessary to define some specific concepts related to object-orientation.
We would need to convince you of the importance of the following concepts.
• Modularity. All the data of a particular object, and the operations that we perform
on this object, are held in one or two files, and can be worked on independently.
• Abstraction. The essential features and functionality of a class are put in one
place and the details of how they work are unimportant to the user of the class.
For example, if you are using a linear system library to solve matrix equations
you should not need to know the precise details of how matrices are laid out in
memory or the exact order that a numerical solver performs its operations. You
should only need to know how to use the functionality of the library.
• Encapsulation. The implementation of an object is kept hidden from the user of
the class. This is not only about clarity (abstracting away the detail). It is also
about preventing the user from accidentally amending internal workings of, for
example, a linear solver, stopping it from working effectively.
• Extensibility. Functionality can be reused with selected parts extended. For exam-
ple, much of the core of a linear solver is in matrix-vector products and scalar
products—this type of functionality need only be implemented once, then other
parts of the program can build on it.
• Polymorphism. The same code can be used for a variety of objects. For example, we
would like to use similar looking C++ code to raise a matrix of complex numbers
to a given power as we would to raise a real number to a given power—even
though the basic arithmetic operations “behind the scenes” are different.
• Inheritance. This, perhaps the most important feature of object-orientation, allows
for code reuse, extensibility and polymorphism. For example, a new linear
solver for singular matrix systems will share many of the features of a basic
linear solver. Inheritance allows the new solver to derive functionality from the
basic solver, and then build on this functionality.
We are not going to discuss these terms in any more detail at this time. It is not that
these things are unimportant. Quite the contrary—all these concepts add up to make
C++ a very powerful language. However, we can cover the basics of programming
without object-orientation. We will describe classes and objects in Chap. 6 and revisit
some of these concepts. Then we can show exactly why inheritance, for instance, is
so powerful when we come to explain it in Chap. 7.