C How to Program 2nd Edition C++ Programming Download Full book in PDF By Paul deitel
C++ has similarities to Java, but comes with many unique characteristics of its own. Jennifer presents the reader with an overview of C++ as well as an introduction to its underlying mechanisms. By the end of this book, you will have a clear understanding of what C++ can do for you. There are no tricky concepts introduced in this text.
In C++, you don’t have static types. You have function references, const, and const void. Functions can be moved, called at different times, called with a particular parameter, and used to create new entities of which some are unaware. When a function is deleted, a pointer to it is kept around. A pointer can also be dereferenced. That’s all there is to C++.
One of the most important parts of C++ is templates. Templates are special code that can be used anywhere in a program without requiring the user to write it by hand. Just like in Java, templates can be specialized to fit a user’s exact specifications. There are literally thousands of different types of templates, each defining just one function. Templates are important in C++ because they enable programmers to define and reuse large parts of their code very quickly.
Another essential component of C++ is the type system. C++ deals specifically with types and their meaning. Each type has a meaning defined in the C++ standard and can only be used in specific situations, which are described in the C++ standard. C++ enforces these rules by standardizing the use of types.
Unlike Java, where classes are simple objects with which the programmer can reuse parts of the program, in C++ classes have a more complex structure. The C++ standard defines the types, which are required, and in what ways they can be used. Types play a crucial role in the type system of C++. Even a class or struct in Java can be used as an lvalue, which can be converted to a real object if and when desired.
A feature of C++ called pre-processor optimization is used extensively by the modern C++ programmer. A pre-processor optimizer takes pre-existing C code and changes it into pre-processed C++ code. This allows the programmer to re-use C++ code, thus saving both memory and time.
A pre-processor optimizer is usually used with a source-level optimizer. The pre-processor passes the source code through various layers of C++ bindings, sometimes with generated optimization, and finally to C. The pre-processor passes the final output as a C program, which can be executed with the assistance of a C compiler. Sometimes, compilers are integrated with the pre-processor to provide a compact execution environment.
Pre-processor optimization is useful for controlling the complexity of the generated code. However, it is only effective in languages that have a single source tree. In a situation where source trees are multiple, pre-processor optimization is not always necessary. In such cases source trees can simply be parallelized. Pre-processor optimization does have its uses, but in many modern C++ programs it is only of use for programmers who want to control the amount of pre-processor optimization.