Skip to main content

2018 | Buch

Beginning C++17

From Novice to Professional

insite
SUCHEN

Über dieses Buch

Learn how to program using the updated C++17 language. You'll start with the basics and progress through step-by-step examples to become a working C++ programmer. All you need are Beginning C++17 and any recent C++ compiler and you'll soon be writing real C++ programs. There is no assumption of prior programming knowledge.
All language concepts that are explained in the book are illustrated with working program examples, and all chapters include exercises for you to test and practice your knowledge. Code downloads are provided for all examples from the text and solutions to the exercises.
This latest edition has been fully updated to the latest version of the language, C++17, and to all conventions and best practices of so-called modern C++. Beginning C++17 also introduces the elements of the C++ Standard Library that provide essential support for the C++17 language.
What You'll LearnDefine variables and make decisions
Work with arrays and loops, pointers and references, strings, and more
Write your own functions, types, and operators
Discover the essentials of object-oriented programming
Use overloading, inheritance, virtual functions and polymorphism
Write generic function templates and class templates
Get up to date with modern C++ features: auto type declarations, move semantics, lambda expressions, and more
Examine the new additions to C++17

Who This Book Is ForProgrammers new to C++ and those who may be looking for a refresh primer on the C++17 programming language in general.

Inhaltsverzeichnis

Frontmatter
Chapter 1. Basic Ideas
Abstract
In this book we sometimes will use certain code in the examples before having explained it in detail. This chapter is intended to help you when this occurs by giving presenting an overview of the major elements of C++ and how they hang together. We’ll also explain a few concepts relating to the representation of numbers and characters in your computer.
Ivor Horton, Peter Van Weert
Chapter 2. Introducing Fundamental Types of Data
Abstract
In this chapter, we’ll explain the fundamental data types that are built into C++. You’ll need these in every program. All of the object-oriented capabilities are founded on these fundamental data types because all the data types that you create are ultimately defined in terms of the basic numerical data your computer works with. By the end of the chapter, you’ll be able to write a simple C++ program of the traditional form: input – process – output.
Ivor Horton, Peter Van Weert
Chapter 3. Working with Fundamental Data Types
Abstract
In this chapter, we expand on the types that we discussed in the previous chapter and explain how variables of the basic types interact in more complicated situations. We also introduce some new features of C++ and discuss some of the ways that these are used.
Ivor Horton, Peter Van Weert
Chapter 4. Making Decisions
Abstract
Decision-making is fundamental to any kind of computer programming. It’s one of the things that differentiates a computer from a calculator. It means altering the sequence of execution depending on the result of a comparison. In this chapter, you’ll explore how to make choices and decisions. This will allow you to validate program input and write programs that can adapt their actions depending on the input data. Your programs will be able to handle problems where logic is fundamental to the solution.
Ivor Horton, Peter Van Weert
Chapter 5. Arrays and Loops
Abstract
An array enables you to work with several data items of the same type using a single name, the array name. The need for this occurs often—when working with a series of temperatures or the ages of a group of people, for example. A loop is another fundamental programming facility. It provides a mechanism for repeating one or more statements as many times as your application requires. Loops are essential in the majority of programs. Using a computer to calculate the company payroll, for example, would not be practicable without a loop. There are several kinds of loop, each with their own particular area of application.
Ivor Horton, Peter Van Weert
Chapter 6. Pointers and References
Abstract
The concepts of pointers and references have similarities, which is why we have put them together in a single chapter. Pointers are important because they provide the foundation for allocating memory dynamically. Pointers can also make your programs more effective and efficient in other ways. Both references and pointers are fundamental to object-oriented programming.
Ivor Horton, Peter Van Weert
Chapter 7. Working with Strings
Abstract
This chapter is about handling textual data much more effectively and safely than the mechanism provided by a C-style string stored in an array of char elements.
Ivor Horton, Peter Van Weert
Chapter 8. Defining Functions
Abstract
Segmenting a program into manageable chunks of code is fundamental to programming in every language.
Ivor Horton, Peter Van Weert
Chapter 9. Function Templates
Abstract
In the section on overloading in the previous chapter, you may have noticed that some of the overloaded functions consisted of exactly the same code. The only difference is the types that appear in the parameter list.
Ivor Horton, Peter Van Weert
Chapter 10. Program Files and Preprocessing Directives
Abstract
his chapter is more about managing code than writing code. We’ll discuss how multiple program files and header files interact and how you manage and control their contents. The material in this chapter has implications for how you define your data types, which you’ll learn about starting in the next chapter.
Ivor Horton, Peter Van Weert
Chapter 11. Defining Your Own Data Types
Abstract
In this chapter, we’ll introduce one of the most fundamental tools in the C++ programmer’s toolbox: classes. We’ll also present some ideas that are implicit in object-oriented programming and show how they are applied.
Ivor Horton, Peter Van Weert
Chapter 12. Operator Overloading
Abstract
In this chapter, you’ll learn how to add support for operators such as add and subtract to your classes so that they can be applied to objects. This will make the types that you define behave more like fundamental data types and offer a more natural way to express some of the operations between objects. You’ve already seen how classes can have member functions that operate on the member variables of an object. Operator overloading enables you to write member functions that enable the basic operators to be applied to class objects.
Ivor Horton, Peter Van Weert
Chapter 13. Inheritance
Abstract
We’ll discuss polymorphism in the next chapter, so what you’ll learn there is an integral part of what inheritance is all about. There are subtleties in inheritance that we’ll tease out using code that shows what is happening.
Ivor Horton, Peter Van Weert
Chapter 14. Polymorphism
Abstract
Polymorphism is such a powerful feature of object-oriented programming that you’ll use it in the majority of your C++ programs. Polymorphism requires you to use derived classes, so the content of this chapter relies heavily on the concepts related to inheritance in derived classes that we introduced in the previous chapter.
Ivor Horton, Peter Van Weert
Chapter 15. Runtime Errors and Exceptions
Abstract
Exceptions are used to signal errors or unexpected conditions in a program. While other error-handling mechanisms do exist, exceptions generally lead to simpler, cleaner code, in which you are less likely to miss an error.
Ivor Horton, Peter Van Weert
Chapter 16. Class Templates
Abstract
Class templates are a powerful mechanism for generating new class types automatically. A significant portion of the C++ Standard Library is built entirely on the ability to define templates. Both function and class templates are used extensively throughout the Library to provide versatile, generic utilities, algorithms, and data structures.
Ivor Horton, Peter Van Weert
Chapter 17. Move Semantics
Abstract
This chapter complements and completes several key topics discussed in the middle parts of the book.
Ivor Horton, Peter Van Weert
Chapter 18. First-Class Functions
Abstract
The term does have a somewhat similar origin. In the 1960s, Christopher Strachey (the same computer language pioneer who first formalized the concepts of lvalues and rvalues, by the way) coined the term when he labeled procedures (functions) as second-class citizens in the programming language ALGOL: “They always have to appear in person and can never be represented by a variable or expression….”
Ivor Horton, Peter Van Weert
Chapter 19. Containers and Algorithms
Abstract
The Standard Library offers an immense number of types and functions, and this number only increases with the release of every new version of the C++ standard. We could not possibly introduce the full range and scope of the Standard Library here in this book.
Ivor Horton, Peter Van Weert
Backmatter
Metadaten
Titel
Beginning C++17
verfasst von
Ivor Horton
Peter Van Weert
Copyright-Jahr
2018
Verlag
Apress
Electronic ISBN
978-1-4842-3366-5
Print ISBN
978-1-4842-3365-8
DOI
https://doi.org/10.1007/978-1-4842-3366-5