Example: confidence

Beginning C++ Programming - Programmer Books

Beginning C++ Programming This is the start of your journey into the most powerfullanguage available to the Programming public Richard Grimes BIRMINGHAM - MUMBAIB eginning C++ Programming Copyright 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, ortransmitted in any form or by any means, without the prior written permission of thepublisher, except in the case of brief quotations embedded in critical articles or effort has been made in the preparation of this book to ensure the accuracy of theinformation presented. However, the information contained in this book is sold withoutwarranty, either express or implied. Neither the author, nor Packt Publishing, and itsdealers and distributors will be held liable for any damages caused or alleged to be causeddirectly or indirectly by this Publishing has endeavoured to provide trademark information about all of thecompanies and products mentioned in this book by the appropriate use of , Packt Publishing cannot guarantee the accuracy of this published: April 2017 Production reference: 1180417 Published by Packt Publishing Place35 Livery StreetBirmingham B3 2PB, Richard GrimesCopy Editor Safis EditingReviewer Angel HernandezProject Coordinator Vaidehi SawantCommissioning Editor Aaron LazarProofreader Safis EditingA

manufacturing industry. He has spoken at 70 international conferences on Microsoft technologies (including C++ and C#) and has written 8 books, 150 articles for programming journals, and 5 training courses for Microsoft. Richard was awarded Microsoft MVP for 10 years (1998-2007). He has a reputation for his deep understanding of the .NET framework

Tags:

  Programming, Beginning, Microsoft, 2007, Beginning c programming

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Beginning C++ Programming - Programmer Books

1 Beginning C++ Programming This is the start of your journey into the most powerfullanguage available to the Programming public Richard Grimes BIRMINGHAM - MUMBAIB eginning C++ Programming Copyright 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, ortransmitted in any form or by any means, without the prior written permission of thepublisher, except in the case of brief quotations embedded in critical articles or effort has been made in the preparation of this book to ensure the accuracy of theinformation presented. However, the information contained in this book is sold withoutwarranty, either express or implied. Neither the author, nor Packt Publishing, and itsdealers and distributors will be held liable for any damages caused or alleged to be causeddirectly or indirectly by this Publishing has endeavoured to provide trademark information about all of thecompanies and products mentioned in this book by the appropriate use of , Packt Publishing cannot guarantee the accuracy of this published: April 2017 Production reference.

2 1180417 Published by Packt Publishing Place35 Livery StreetBirmingham B3 2PB, Richard GrimesCopy Editor Safis EditingReviewer Angel HernandezProject Coordinator Vaidehi SawantCommissioning Editor Aaron LazarProofreader Safis EditingAcquisition Editor Nitin DasanIndexer Tejal Daruwale Soni Content Development Editor Zeeyan PinheiroGraphics Abhinash SahuTechnical Editor Pavan RamchandaniProduction Coordinator Shraddha Falebhai About the AuthorRichard Grimes has been Programming in C++ for 25 years, working on projects as diverseas scientific control and analysis and finance analysis to remote objects for the automotivemanufacturing industry. He has spoken at 70 international conferences on Microsofttechnologies (including C++ and C#) and has written 8 Books , 150 articles for programmingjournals, and 5 training courses for microsoft . Richard was awarded microsoft MVP for 10years (1998- 2007 ). He has a reputation for his deep understanding of the.

3 NET frameworkand C++ and the frank way in which he assesses new my wife Ellinor: it is only with your love and support that I am able to do anything atallAbout the ReviewerAngel Hernandez is a highly regarded senior solutions, architect and developer with over15 years of experience, mainly in the consulting space. He is an 11-time microsoft (2006-2016) MVP award recipient in Visual Studio and Development Technologies category(formerly, Visual C++), and he is currently a member of the microsoft MVP ReconnectProgram. Angel is also a TOGAF practitioner. He has deep knowledge of microsoft andopen source technologies (*nix Systems), and he's an expert in managed and nativelanguages, C# and C++ being his favorites. He can be reached at h t t p ://w w w . a n g e l h e r n a n de z m . c o m .I d like to thank, first and foremost, God and his son Jesus; Packt and the author for givingme the opportunity to review this book; and my family, Mery, Miranda, and Mikaela (the3Ms) for being understanding and patient with support files and downloads related to your book, please visit you know that Packt offers eBook versions of every book published, with PDF andePub files available?

4 You can upgrade to the eBook version at and as aprint book customer, you are entitled to a discount on the eBook copy. Get in touch with usat for more , you can also read a collection of free technical articles, sign up for arange of free newsletters and receive exclusive discounts and offers on Packt Books t t p s ://w w w . p a c k t p u b . c o m /m a p tGet the most in-demand software skills with Mapt. Mapt gives you full access to all Packtbooks and video courses, as well as industry-leading tools to help you plan your personaldevelopment and advance your subscribe?Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browserCustomer FeedbackThanks for purchasing this Packt book. At Packt, quality is at the heart of our editorialprocess. To help us improve, please leave us an honest review on this book's Amazon pageat h t t p s ://w w w.

5 A m a z o n . c o m /d p you'd like to join our team of regular reviewers, you can e-mail us We award our regular reviewers with free eBooks andvideos in exchange for their valuable feedback. Help us be relentless in improving ourproducts!Table of ContentsCustomer Feedback7 Preface1 Chapter 1: Starting with C++7 What will you find in this chapter?8 What is C++?8 Installing Visual C++9 Setting up9 Downloading the installation files10 Installing Visual Studio10 Registering with Microsoft14 Examining C++ projects16 Compilers17 Linking the code18 Source files18A simple example19 Creating source files21 Compiling the code23 Passing parameters between the command-line and an executable25 The preprocessor and symbols28 Defining constants28 Using macros31 Using symbols31 Using pragmas33 Dependencies34 Libraries34 Pre-compiled headers35 Project structure36 Managing dependencies37 Makefiles38 Writing a simple project39 The project structure39 Creating the precompiled header40 Creating the main file42 Using input and output streams43 Using time functions44 Building the executable45[ ii ]Testing the code46 Changing the project47 Summary47 Chapter 2.

6 Understanding Language Features48 Writing C++48 Using white space48 Formatting code49 Writing statements51 Working with expressions51 Using the comma operator53 Using types and variables53 Using constants and literals55 Defining constants55 Using constant expressions57 Using enumerations58 Declaring pointers59 Using namespaces61C++ scoping of variables65 Using operators68 Exploring the built-in operators70 Arithmetic operators70 Increment and decrement operators71 Bitwise operators72 Boolean operators73 Bitwise shift operators75 Assignment operators76 Controlling execution flow76 Using conditional statements76 Selecting79 Looping82 Looping with iteration82 Conditional loops87 Jumping88 Using C++ language features88 Summary95 Chapter 3: Exploring C++ Types96 Exploring built-in types96 Integers97 Specifying integer literals100 Using bitset to show bit patterns101 Determining integer byte order102[ iii ]

7 Floating point types103 Specifying floating point literals104 Characters and strings104 Character types105 Using character macros106 Specifying character literals107 Specifying string literals108 Unicode literals110 Raw strings110 String byte order112 Boolean113void113 Initializers114 Default values115 Declarations without a type117 Storage classes119 Using type aliases121 Aggregating data in record types122 Structures123 Initializing124 Structure fields125 Using structure names126 Determining alignment127 Storing data in the same memory with unions130 Accessing runtime type information132 Determining type limits132 Converting between types132 Type conversions133 Promoting conversions133 Narrowing conversions133 Narrowing to bool134 Converting signed types135 Casting135 Casting away const-ness136 Casting without runtime checks137 Casting pointers without runtime checks138 Casting with runtime checks138 Casting with list initializer139 Using C casts140 Using C++ types140 Summary148 Chapter 4.

8 Working with Memory, Arrays, and Pointers149 Using memory in C++149[ iv ]Using C++ pointer syntax150 Using null pointers152 Types of memory153 Pointer arithmetic155 Using arrays157 Function parameters158 Multidimensional arrays160 Passing multidimensional arrays to functions161 Using arrays of characters162 Comparing strings162 Preventing buffer overruns163 Using pointers in C++165 Accessing out of bounds165 Pointers to deallocated memory166 Converting pointers166 Constant pointers167 Changing the type pointed to168 Allocating memory in code169 Allocating individual objects169 Allocating arrays of objects170 Handling failed allocations170 Using other versions of the new operator171 Memory lifetime172 The Windows SDK and pointers173 Memory and the C++ Standard Library176 Standard Library arrays176 Using the stack-based array class176 Using the dynamically allocated vector class178 References178 Constant references180 Returning references180 Temporaries and references181

9 The rvalue references182 Ranged for and references185 Using pointers in practice187 Creating the project189 Adding a task object to the list190 Deleting the task list192 Iterating the task list193 Inserting items194[ v ]Summary197 Chapter 5: Using Functions198 Defining C++ functions198 Declaring and defining functions198 Specifying linkage200 Inlining200 Determining the return type201 Naming the function202 Function parameters202 Specifying exceptions202 Function body203 Using function parameters203 Passing Initializer lists204 Using default parameters204 Variable number of parameters205 Initializer lists205 Argument lists207 Function features209 Call stack209 Specifying calling conventions210 Using C linkage210 Specifying how the stack Is maintained211 Using recursion211 Overloading functions212 Functions and scope213 Deleted functions213 Passing by value and passing by reference214 Designing functions216 Pre- and post-conditions216 Using invariants217 Function pointers218 Remember the parentheses!

10 218 Declaring function pointers218 Using function pointers220 Templated functions222 Defining templates223 Using template parameter values225 Specialized templates227 Variadic templates229[ vi ]Overloaded operators231 Function objects234 Introducing lambda expressions237 Using functions in C++239 Summary244 Chapter 6: Classes246 Writing classes246 Reviewing structures247 Defining classes247 Defining class behavior248 Using the this pointer249 Using the scope resolution operator250 Defining class state250 Creating objects252 Construction of objects253 Defining constructors253 Delegating constructors255 Copy constructor255 Converting between types256 Making friends256 Marking constructors as explicit258 Destructing objects258 Assigning objects260 Move semantics262 Declaring static members263 Defining static members263 Using static and global objects264 Named constructors265 Nested classes266 Accessing const objects267 Using objects with pointers268 Getting pointers to object members268 Operator overloading269 Defining function classes272 Defining conversion operators276 Managing resources277 Writing wrapper classes278 Using smart pointers278 Managing exclusive ownership279 Sharing ownership283 Handling dangling


Related search queries