Packt.Advanced.Cplusplus.1838821139.pdf

所需积分/C币:28 2019-11-03 10:35:00 16.14MB PDF
收藏 收藏
举报

Title: Advanced C++: Master the technique of confidently writing robust C++ code Author: Brian Price, Gazihan Alankus, Olena Lizina, Rakesh Mane, Vivek Nagarajan Length: 762 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2019-10-31 ISBN-10: 1838821139 ISBN-13: 97818
Advanced c++ Copyright o 2019 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information Authors: Gazihan alankus, Olena lizina, Rakesh Mane, vivek nagarajan and brian price Technical Reviewers: Anil Achary and Deepak Selvakumar Managing Editor: Bhavesh Bangera Acquisitions Editors: Kunal Sawant, Koushik Sen, and Sneha Shinde Production Editor: Samita Arang Editorial Board: Shubhopriya Banerjee, Bharat Botle, Ewan Buckingham, Mahesh dhyani, Manasa Kumar, alex mazonowicz, Bridget neale dominic pereira Shiny Poojary, Abhisekh Rane, Erol Staveley, Ankita Thakur, Nitesh Thakur, and Jonathan Wray First Published: October 2019 Production Reference: 1311019 ISBN:978-1-83882-113-5 Published by packt Publishing ltd Livery Place, 35 Livery Street Birmingham b 3 2PB, UK Table of contents Preface Chapter 1: anatomy of Portable c++ Software Introduction Managing C++ Projects The code- Build-Test- Run Loop………… 2334 Building a Cmake Project Exercise 1: Using CMake to Generate Ninja Build Files mporting a CMake Project into Eclipse CDt…… 589 EXercise 2: Importing the CMake File into Eclipse CDT Exercise 3: Adding new Source files to CMake and Eclipse CDt 13 Activity1: Adding a New Source- Header File Pair to the Project…………16 Unit Testing Preparing for the Unit Tests…… 17 Exercise4: Preparing Our Project for Unit Testing…………18 Building, Running, and Writing Unit Tests 19 Exercise 5: Building and running tests 20 Exercise 6: Testing the Functionality of Code 26 Activity2: Adding a New Class and Its Test…………… 30 Understanding Compilation, Linking, and object File Contents..... 32 Compilation and Linking Steps ∴32 Exercise 7: Identifying Build Steps 32 The Linking Step……… 39 Diving Deeper; Viewing object Files……… 40 Exercise 8: Exploring compiled Code 灬41 Debugging C++Code…………,…,…,…,…,…,…,…,…,…,…,,…,,…,,…,,…,…,…46 EXercise 9: Debugging with Eclipse CDt 47 Writing Readable Code 56 dentation and Formatting……… 56 Use Meaningful Names as Identifiers,…,,…… 58 Keeping algorithms Clear and Simple 0 EXercise 10: Making Code Readable 62 Activity 3: Making Code More readable..... 66 Summary 68 Chapter 2A: No ducks allowed- Types and deduction ntroduction∴……72 C++ Types…… 73 C++ Fundamental Types 73 C++ Literals灬 Specifying Types-Variables 74 EXercise 1: Declaring Variables and Exploring Sizes 76 Specifying Types - Functions 。鲁鲁自鲁鲁·。。。。 86 Exercise 2: Declaring Functions 88 Pointer Types..... 90 Exercise3: Declaring and Using Pointers……………………………………95 Creating User Types.................................... 99 Enumerations 99 Exercise 4: Enumerations -old and new school ···。···· 104 Structures and classes 107 Fraction class 108 Constructors, Initialization and destructors.. 109 Class special member Functions mplicit Versus Explicit Constructors……………,…,,…,,…,,…,,…………,12 Class special member Functions -Compiler Generation rules 113 Defaulting and Deleting Special Member Functions…………………………13 Rule of three/five and rule of zero ●· ∴1115 Constructors -Initializing the object 115 Exercise 5: Declaring and Initializing Fractions 118 Values versus references and const ggggg 120 Exercise6: Declaring and Using Reference Types………,… 123 Implementing Standard Operators 124 Implementing the Output Stream Operator(<)…………,……………,125 Structuring our Code……,126 Exercise 7: Adding Operators to the Fraction Class 127 Function overloading ng 131 Classes, Structs, and unions∴…132 Activity1: Graphics Processing…… 134 Summary…………,…,…,…,…,……………………,137 Chapter 2B: No Ducks Allowed -Templates and deduction 139 Introduction 140 Inheritance, Polymorphism, and interfaces…………,…,…,,…,,…,140 Inheritance and Access Specifiers………,…,…,…,…,…,…,…,…,,…,…,…,,……,146 Abstract classes and interfaces 146 Exercise1: Implementing Game Characters with Polymorphism………,147 Classes, Structs and Unions Revisited .. 151 Visibility, Lifetime, and Access 152 Namespaces……,…,…,,…,…,…,…,,…,…,,…,,…,…,,…,…,……,…,155 Templates -Generic Programming D鲁。自。。.。。·。。。鲁。。音。。。。。自。。。 156 What is Generic Programming? 157 Introducing C++ Templates 157 C++ Pre-Packaged Templates 159 Type Aliases- typedef and using ,161 Exercise2: Implementing Aliases……… 162 Templates-More than Generic Programming 163 Substitution failure Is not an error-Sfinae 164 Floating-Point Representations 168 Constexpr if Expressions 169 Non-Type Template Arguments ∴170 EXercise 3: Implementing Stringify-specialization Versus constexpr.171 Function Overloading revisited 174 Template Type Deduction 174 Displaying the Deduced Types 175 Template Type Deduction -the Details 176 SF| NAE Expression and Trailing Return Types……………,…,,………183 Class Templates 186 Exercise4: Writing a Class Template…… 186 Activity 1: Developing a Generic"contains"Template Function 190 Summary 191 Chapter 3: No Leaks allowed - Exceptions and resources 193 ntroduction 194 Variable Scope and lifetime ∴194 Exceptions in C++ ∴200 The Need for Exceptions..,..,,..,,,,.,.,,…,,…,…,…,…,200 Stack Unwinding 206 Exercise1: Implementing exceptions in Fraction and Stack……………,206 What Happens When an Exception is Thrown?…… 212 Throw-by-Value or throw-by-Pointer.................... 212 Standard Library Exceptions 213 Catching Exceptions 214 Exercise 2: Implementing Exception Handlers 216 CMake Generator Expressions………………………………,218 Exception Usage guidelines 219 Resource Management (in an Exceptional World)..... 219 Resource acquisition Is Initialization ....................... 220 Exercise3: Implementing RAll for Memory and File Handles……………,223 Special Coding Techniques n226 C++ doesn' Need finally!………………….….…,……………………27 RAll and the stl 227 Who Owns this object? 227 Temporary objects 229 Move semantics∴229 Implementing a Smart Pointer 230 STL Smart Pointers∴ 235 std: unique_ptr…………… 236 std:shared_ptr 237 std:ieak_ptr… 238 Smart Pointers and Calling Functions ∴241 Exercise 4: Implementing RAll with STL Smart Pointers n245 Rule of zero/Five- A Different Perspective…………,…,…,………,………,250 Activity 1: Implementing graphics Processing with RAll and move 252 When is a function called? 253 Which function to call 254 Identifiers 255 Names 255 Name lookup 256 Argument- Dependent Lookup……………,,…,……,…,…,………,256 Caveat Emptor ∴258 Exercise5: mplementing Templates to Prevent ADL Issues……,…,260 Implicit Conversion… 262 Explicit- Preventing Implicit Conversion 262 Contextual Conversion 265 Exercise 6: Implicit and explicit Conversions 266 Activity2: mplementing classes for Date Calculations……………………,270 Summary 271 Chapter 4: Separation of concerns- Software Architecture functions and variadic templates 273 Introduction 274 The pointer to Implementation(PIMPL)Idiom .... n274 ogical and Physical Dependencies……… 274 The Pointer to Implementation(PIMPL)Idiom 276 Advantages and Disadvantages of PIMPL 280 mplementing PIMPL with unique_ptr<>……,…,…,…,…,…,…,…,…,………………280 unique ptr<> PlMPl Special functions 283 Exercise1: Implementing a Kitchen with unique_ptr<>………………………,286 Function Objects and Lambda Expressions…………………………,…290 Function pointers∴ n290 What is a function object? 294 Exercise 2: Implementing function objects……… 297 std: function<> template ∴299 EXercise 3: Implementing callbacks with std: function 302 What is a Lambda Expression? 305 Capturing data into Lambdas…………,…,…,…,…,…,…,…,…,…,……,…,307 Exercise 4: Implementing lambdas 309 Variadic templates 313 Activity 1: Implement a multicast event handler 317 Summary…… 318 Chapter 5: The Philosophers Dinner- Threads and Concurrency 321 ntroduction…322 Synchronous, asynchronous, and threaded execution 323 Concurrency… 323 Parallelism 324 Synchronous Execution.............................. 327 Asynchronous EXecution 330 Exercise1: Creating Threads in a Different Way…………,…,… 336 Review Synchronization Data hazards and race conditions..... 340 Exercise 2: Writing an Example of race conditions 342 Data hazards 346 RAW Dependency 346 WAR Dependency 347 WAW Dependency………,…,…,…,…,…,…,…,…,…,…,,…,…,348 Resource Synchronization…,,.,,…,,,…,…,…,………,,349 Event Synchronization 352 Deadlock ∴355 Move Semantics for Multithreading Closures 356 Exercise3: Moving Objects to a Thread Function………… 359

...展开详情
试读 127P Packt.Advanced.Cplusplus.1838821139.pdf
立即下载 低至0.43元/次 身份认证VIP会员低至7折
一个资源只可评论一次,评论内容不能少于5个字
caohongfei881 书清晰,但书的内容不咋地
2020-08-19
回复
上传资源赚积分or赚钱
最新推荐
Packt.Advanced.Cplusplus.1838821139.pdf 28积分/C币 立即下载
1/127
Packt.Advanced.Cplusplus.1838821139.pdf第1页
Packt.Advanced.Cplusplus.1838821139.pdf第2页
Packt.Advanced.Cplusplus.1838821139.pdf第3页
Packt.Advanced.Cplusplus.1838821139.pdf第4页
Packt.Advanced.Cplusplus.1838821139.pdf第5页
Packt.Advanced.Cplusplus.1838821139.pdf第6页
Packt.Advanced.Cplusplus.1838821139.pdf第7页
Packt.Advanced.Cplusplus.1838821139.pdf第8页
Packt.Advanced.Cplusplus.1838821139.pdf第9页
Packt.Advanced.Cplusplus.1838821139.pdf第10页
Packt.Advanced.Cplusplus.1838821139.pdf第11页
Packt.Advanced.Cplusplus.1838821139.pdf第12页
Packt.Advanced.Cplusplus.1838821139.pdf第13页
Packt.Advanced.Cplusplus.1838821139.pdf第14页
Packt.Advanced.Cplusplus.1838821139.pdf第15页
Packt.Advanced.Cplusplus.1838821139.pdf第16页
Packt.Advanced.Cplusplus.1838821139.pdf第17页
Packt.Advanced.Cplusplus.1838821139.pdf第18页
Packt.Advanced.Cplusplus.1838821139.pdf第19页
Packt.Advanced.Cplusplus.1838821139.pdf第20页

试读结束, 可继续阅读

28积分/C币 立即下载 >