Concepts of Programming Languages

(Sean Pound) #1
In 2002, Microsoft released its .NET computing platform, which included
a new version of C++, named Managed C++, or MC++. MC++ extends C++
to provide access to the functionality of the .NET Framework. The additions
include properties, delegates, interfaces, and a reference type for garbage-
collected objects. Properties are discussed in Chapter 11. Delegates are briefly
discussed in the introduction to C# in Section 2.19. Because .NET does not
support multiple inheritance, neither does MC++.

2.16.2 Language Overview


Because C++ has both functions and methods, it supports both procedural and
object-oriented programming.
Operators in C++ can be overloaded, meaning the user can create opera-
tors for existing operators on user-defined types. C++ methods can also be
overloaded, meaning the user can define more than one method with the same
name, provided either the numbers or types of their parameters are different.
Dynamic binding in C++ is provided by virtual methods. These methods
define type-dependent operations, using overloaded methods, within a collec-
tion of classes that are related through inheritance. A pointer to an object of
class A can also point to objects of classes that have class A as an ancestor. When
this pointer points to an overloaded virtual method, the method of the current
type is chosen dynamically.
Both methods and classes can be templated, which means that they can be
parameterized. For example, a method can be written as a templated method
to allow it to have versions for a variety of parameter types. Classes enjoy the
same flexibility.
C++ supports multiple inheritance. It also includes exception handling that
is significantly different from that of Ada. One difference is that hardware-
detectable exceptions cannot be handled. The exception-handling constructs
of Ada and C++ are discussed in Chapter 14.

2.16.3 Evaluation


C++ rapidly became and remains a widely used language. One factor in its
popularity is the availability of good and inexpensive compilers. Another factor
is that it is almost completely backward compatible with C (meaning that C
programs can be, with few changes, compiled as C++ programs), and in most
implementations it is possible to link C++ code with C code—and thus rela-
tively easy for the many C programmers to learn C++. Finally, at the time C++
first appeared, when object-oriented programming began to receive widespread
interest, C++ was the only available language that was suitable for large com-
mercial software projects.
On the negative side, because C++ is a very large and complex language,
it clearly suffers drawbacks similar to those of PL/I. It inherited most of the
insecurities of C, which make it less safe than languages such as Ada and
Java.

2.16 Combining Imperative and Object-Oriented Features: C++ 89
Free download pdf