Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Expert C++
Expert C++

Expert C++: Become a proficient programmer by learning coding best practices with C++17 and C++20's latest features

eBook
$9.99 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Expert C++

Introduction to Building C++ Applications

Programming languages differ by their program execution model; the most common are interpreted and compiled languages. Compilers translate source code into machine code, which a computer can run without intermediary support systems. Interpreted language code, on the other hand, requires support systems, interpreters, and the virtual environment to work.

C++ is a compiled language, which makes programs run faster than their interpreted counterparts. While C++ programs should be compiled for each platform, interpreted programs can operate cross-platform.

We are going to discuss the details of a program-building process, starting with the phases of processing the source code – done by the compiler- and ending with the details of the executable file (the compiler's output). We will also learn why a program built for one platform...

Technical requirements

Introduction to C++20

C++ has evolved over the years and now it has a brand-new version, C++20. Since C++11, the C++ standard has grown the language feature set tremendously. Let's look at notable features in the new C++20 standard.

Concepts

Concepts are a major feature in C++20 that provides a set of requirements for types. The basic idea behind concepts is the compile-time validation of template arguments. For example, to specify that the template argument must have a default constructor, we use the default_constructible concept in the following way:

template <default_constructible T>
void make_T() { return T(); }

In the preceding code, we missed the typename keyword. Instead, we set a concept that describes the...

Building and running programs

You can use any text editor to write code, because, ultimately, code is just text. To write code, you are free to choose between simple text editors such as Vim, or an advanced integrated development environment (IDE) such as MS Visual Studio. The only difference between a love letter and source code is that the latter might be interpreted by a special program called a compiler (while the love letter cannot be compiled into a program, it might give you butterflies in your stomach).

To mark the difference between a plain text file and source code, a special file extension is used. C++ operates with the .cpp and .h extensions (you may also occasionally encounter .cxx and .hpp as well). Before getting into the details, think of the compiler as a tool that translates the source code into a runnable program, known as an executable file or just an executable...

Understanding preprocessing

A preprocessor is intended to process source files to make them ready for compilation. A preprocessor works with preprocessor directives, such as #define, #include, and so on. Directives don't represent program statements, but they are commands for the preprocessor, telling it what to do with the text of the source file. The compiler cannot recognize those directives, so whenever you use preprocessor directives in your code, the preprocessor resolves them accordingly before the actual compilation of the code begins. For example, the following code will be changed before the compiler starts to compile it:

#define NUMBER 41 
int main() {
int a = NUMBER + 1;
return 0;
}

Everything that is defined using the #define directive is called a macro. After preprocessing, the compiler gets the transformed source in this form:

int main() { 
int a = 41 ...

Understanding Compiling

The C++ compilation process consists of several phases. Some of the phases are intended to analyze the source code, and others generate and optimize the target machine code. The following diagram shows the phases of compilation:

Let's look at each of these phases in detail.

Tokenization

The analysis phase of the compiler aims to split the source code into small units called tokens. A token may be a word or just a single symbol, such as = (the equals sign). A token is the smallest unit of the source code that carries meaningful value for the compiler. For example, the expression int a = 42; will be divided into the tokens int, a, =, 42, and ;. The expression isn't just split by spaces, because...

Introducing Linking

The compiler outputs an object file for each compilation unit. In the previous example, we had three .cpp files and the compiler produced three object files. The task of the linker is to combine these object files together into a single object file. Combining files together results in relative address changes; for example, if the linker puts the rect.o file after main.o, the starting address of rect.o becomes 0x04 instead of the previous value of 0x00:

code: 
0x00 main
0x01 Rect r;
0x02 _Rect_init_(&r, 3.1, 4.05);
0x03 printf("%d\n", _Rect_get_area(&r));
0x04 _Rect_init_
0x05 side1_ = s1
0x06 side2_ = s2
0x07 return
0x08 _Rect_get_area_
0x09 register = side1_
0x0A reg_multiply side2_
0x0B return
information (symbol table):
main: 0x00
_Rect_init_: 0x04
printf: ????
_Rect_get_area_: 0x08

_Rect_init_: 0x04
_Rect_get_area_...

Summary

In this chapter, we touched on a few of the many new features of C++20 and are now ready to dive deeper into the language. We discussed the process of building a C++ application and its compilation phases. This includes analyzing the code to detect syntactical and grammatical errors, generating intermediate code to make optimizations, and finally, generating the object file that will be linked together with other generated object files to form the final executable file.

In the next chapter, we will learn about C++ data types, arrays, and pointers. We will also gain an understanding of what pointers are and look at low-level details of conditionals.

Questions

  1. What is the difference between a compiler and an interpreter?
  2. List the program compilation phases.
  3. What does the preprocessor do?
  4. What are the tasks of the linker?
  5. What is the difference between statically and dynamically linked libraries?

Further reading

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Design professional-grade, maintainable apps by learning advanced concepts such as functional programming, templates, and networking
  • Apply design patterns and best practices to solve real-world problems
  • Improve the performance of your projects by designing concurrent data structures and algorithms

Description

C++ has evolved over the years and the latest release – C++20 – is now available. Since C++11, C++ has been constantly enhancing the language feature set. With the new version, you’ll explore an array of features such as concepts, modules, ranges, and coroutines. This book will be your guide to learning the intricacies of the language, techniques, C++ tools, and the new features introduced in C++20, while also helping you apply these when building modern and resilient software. You’ll start by exploring the latest features of C++, and then move on to advanced techniques such as multithreading, concurrency, debugging, monitoring, and high-performance programming. The book will delve into object-oriented programming principles and the C++ Standard Template Library, and even show you how to create custom templates. After this, you’ll learn about different approaches such as test-driven development (TDD), behavior-driven development (BDD), and domain-driven design (DDD), before taking a look at the coding best practices and design patterns essential for building professional-grade applications. Toward the end of the book, you will gain useful insights into the recent C++ advancements in AI and machine learning. By the end of this C++ programming book, you’ll have gained expertise in real-world application development, including the process of designing complex software.

Who is this book for?

This C++ book is for experienced C++ developers who are looking to take their knowledge to the next level and perfect their skills in building professional-grade applications.

What you will learn

  • Understand memory management and low-level programming in C++ to write secure and stable applications
  • Discover the latest C++20 features such as modules, concepts, ranges, and coroutines
  • Understand debugging and testing techniques and reduce issues in your programs
  • Design and implement GUI applications using Qt5
  • Use multithreading and concurrency to make your programs run faster
  • Develop high-end games by using the object-oriented capabilities of C++
  • Explore AI and machine learning concepts with C++

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 10, 2020
Length: 606 pages
Edition : 1st
Language : English
ISBN-13 : 9781838554767
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 10, 2020
Length: 606 pages
Edition : 1st
Language : English
ISBN-13 : 9781838554767
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 198.97
Modern C++ Programming Cookbook
$94.99
C++ High Performance
$59.99
Expert C++
$43.99
Total $ 198.97 Stars icon
Banner background image

Table of Contents

21 Chapters
Section 1: Under the Hood of C++ Programming Chevron down icon Chevron up icon
Introduction to Building C++ Applications Chevron down icon Chevron up icon
Low-Level Programming with C++ Chevron down icon Chevron up icon
Details of Object-Oriented Programming Chevron down icon Chevron up icon
Understanding and Designing Templates Chevron down icon Chevron up icon
Memory Management and Smart Pointers Chevron down icon Chevron up icon
Section 2: Designing Robust and Efficient Applications Chevron down icon Chevron up icon
Digging into Data Structures and Algorithms in STL Chevron down icon Chevron up icon
Functional Programming Chevron down icon Chevron up icon
Concurrency and Multithreading Chevron down icon Chevron up icon
Designing Concurrent Data Structures Chevron down icon Chevron up icon
Designing World-Ready Applications Chevron down icon Chevron up icon
Designing a Strategy Game Using Design Patterns Chevron down icon Chevron up icon
Networking and Security Chevron down icon Chevron up icon
Debugging and Testing Chevron down icon Chevron up icon
Graphical User Interface with Qt Chevron down icon Chevron up icon
Section 3: C++ in the AI World Chevron down icon Chevron up icon
Using C++ in Machine Learning Tasks Chevron down icon Chevron up icon
Implementing a Dialog-Based Search Engine Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.1
(9 Ratings)
5 star 22.2%
4 star 22.2%
3 star 11.1%
2 star 33.3%
1 star 11.1%
Filter icon Filter
Top Reviews

Filter reviews by




KARAN Jun 19, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Nice book , advanced concepts very much satisfied with the contents.
Subscriber review Packt
Andranik Dec 10, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is very understandable.And contains important information
Amazon Verified review Amazon
cygnus.x1 Jan 20, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good book, but not quite perfect.
Amazon Verified review Amazon
FAm Dec 19, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Really great book to master modern C++. It covers and explains the concepts well it also tries to explain in the perspective of compiler. I gave 4 ⭐ just because I faced some wrong examples which even didn't get compiled under C++20 and lower compilers
Amazon Verified review Amazon
George Apr 28, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This book explains many basic concepts from base C++ (aka C++11) and doesn't explains what some newer concepts are, even though they are used. The book also leads you into thinking that it will work through a project within a chapter, but actually doesn't do that, instead only doing small snippets of the project and explaining other parts in text only (it feals like they were told the book could only be so many pages long and constantly reminds you of this). The AI chapters is also severely missing in content, both conceptually and in code examples.The early part of this book focuses in on how the compiler works and how it changes you code to look like, but then says how different compilers may work differently.The book also mentions that it would cover certain C++20 content that it barely mentions and doesn't explain how to use it or hiw it is better than a method(s) that already existed. This is especially felt, in my opinion, in the section that mentions (it doesn't truly cover) ranges. I have little experience with functional style programming, and, in comparison to OOP, neither does many C++ programs. Similarly, concepts are shown, but it doesn't really show how to make your own.The section, in my opinion, that has the best coverage is the chapter that covers multi-threading, but it was still lacking in its explanation on coroutines. Similarly, template metaprogramming is also covered well, but I feel the author(s) didn't use any of the newer additions to C++ that I expect, but haven't had time to test and see, to work.The section on GUIs focused on just one library, Qt, and I feel other libraries should have been looked at. It also didn't do a good job at showing what different widgets/layouts looked like.I think that this would be a good book for an intermediate C++ program with plenty of free time to further develop the projects shown, but it shouldn't be the only resources used or you will come out knowing little or nothing about some content.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.