Wrox press professional c++ 3rd (2014) kho tài liệu bách khoa

987 537 0
Wrox press professional c++ 3rd (2014) kho tài liệu bách khoa

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

ffirs.indd 13 11-08-2014 11:29:09 PROFESSIONAL C++ INTRODUCTION xli ➤➤PART I INTRODUCTION TO PROFESSIONAL C++ CHAPTER A Crash Course in C++ and the STL CHAPTER Working with Strings 47 CHAPTER Coding with Style 57 ➤➤PART II PROFESSIONAL C++ SOFTWARE DESIGN CHAPTER Designing Professional C++ Programs 79 CHAPTER Designing with Objects 107 CHAPTER Designing for Reuse 127 ➤➤PART III CODING THE PROFESSIONAL WAY CHAPTER Gaining Proficiency with Classes and Objects 143 CHAPTER Mastering Classes and Objects 177 CHAPTER Discovering Inheritance Techniques 217 CHAPTER 10 C++ Quirks, Oddities, and Incidentals 273 CHAPTER 11 Writing Generic Code with Templates 315 CHAPTER 12 Demystifying C++ I/O 345 CHAPTER 13 Handling Errors 369 CHAPTER 14 Overloading C++ Operators 411 CHAPTER 15 Overview of the C++ Standard Library 443 CHAPTER 16 Understanding Containers and Iterators 467 CHAPTER 17 Mastering STL Algorithms 531 CHAPTER 18 String Localization and Regular Expressions 575 CHAPTER 19 Additional Library Utilities 601 ffirs.indd 11-08-2014 11:29:07 ➤➤PART IV MASTERING ADVANCED FEATURES OF C++ CHAPTER 20 Customizing and Extending the STL 627 CHAPTER 21 Advanced Templates 673 CHAPTER 22 Memory Management 707 CHAPTER 23 Multithreaded Programming with C++ 741 ➤➤PART V C++ SOFTWARE ENGINEERING CHAPTER 24 Maximizing Software Engineering Methods 781 CHAPTER 25 Writing Efficient C++ 801 CHAPTER 26 Conquering Debugging 827 APPENDIX A C++ Interviews 863 APPENDIX B Annotated Bibliography 885 APPENDIX C Standard Library Header Files 895 INDEX 903 ffirs.indd 11-08-2014 11:29:07 Professional C++ ffirs.indd 11-08-2014 11:29:07 ffirs.indd 11-08-2014 11:29:07 PROFESSIONAL C++ Third Edition Marc Gregoire ffirs.indd 11-08-2014 11:29:08 Professional C++, Third Edition Published by John Wiley & Sons, Inc 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2014 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-85805-9 ISBN: 978-1-118-85806-6 (ebk) ISBN: 978-1-118-85813-4 (ebk) Manufactured in the United States of America 10 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600 Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose No warranty may be created or extended by sales or promotional materials The advice and strategies contained herein may not be suitable for every situation This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services If professional assistance is required, the services of a competent professional person should be sought Neither the publisher nor the author shall be liable for damages arising herefrom The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002 Wiley publishes in a variety of print and electronic formats and by print-on-demand Some material included with standard print versions of this book may not be included in e-books or in print-on-demand If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com For more information about Wiley products, visit www.wiley.com Library of Congress Control Number: 2014941048 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc and/or its affiliates, in the United States and other countries, and may not be used without written permission [Insert third-party trademark information] All other trademarks are the property of their respective owners John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book ffirs.indd 11-08-2014 11:29:08 Dedicated to my parents, who are always there for me —Marc Gregoire ffirs.indd 11-08-2014 11:29:08 ffirs.indd 11-08-2014 11:29:08 overloading operators – parent destructors deleting overloaded, 196 operator+ method, 204–205 operator+ method (global), 206–207 operators arithmetic, 207–209 implementing overloaded, 243 superclass method, 258–259 overloading operators, 136, 155–156, 359–360 allocation/deallocation operators, 436–442 argument types, 414 arithmetic operators increment/decrement, 420–421 unary minus and unary plus, 420 behavior choices, 415 binary logical operators, 421–422 bitwise operators, 421–422 comparison operators, 210–211 dereferencing operators, 429–432 extraction operators, 422–423 function-call operator, 428–429 insertion operators, 422–423 limitations, 412–413 operator delete, 437–439 operators not to overload, 415 overloadable operators, 415–418 placement new, 437 reasons for, 412 return types, 414–415 subscripting operator, 423–428 non-integral array indices, 427–428 read-only access, 426–427 type building, 211 use, 136 override keyword, 252 overriding behaviors, 115 methods, 222–225 changing parameters, 250–252 changing return type, 249–250 clients and, 223–225 overloaded superclass method, 258–259 preventing, 225 private superclass method, 259–260 static methods, 257–258 superclass method access level, 261–263 superclass method arguments, 260–261 syntax, 223 throw list, 385–386 virtual, 265–266 what( ), 340 P packets, buffers, 499–501 pair class, 504–505 parallel hierarchies, 249 parameter packs, 694 parameters, 316 Allocator, 473 const keyword, 287 const keyword and, 32 const reference parameters, 32–33 default, 197 functions, 22 lambda expressions, 536, 541 overridden methods, 250–252 references, 276–277, 279–281 template template parameters, 676–678 templates, 316 integer non-type parameters, 327–329 method templates, 332–334 non-type parameters, 327–329, 678–679 parameter packs, 694 type parameters, 674–676 vector, 473 parent classes, 218 parent constructors, 229–230 private, 270 protected, 270 references, 232–234 parent constructors, 229–230 parent destructors, 230–232 925 bindex.indd 925 11-08-2014 11:26:26 parenthese in code – programming parenthese in code, 74 partial specialization classes, 679–683 functions, 683–684 pass-by-reference, efficiency, 804–805 passing objects, by reference, 164–165 by value, disallowing, 188 variables by reference, 27 by value, 27 pattern-matching, 445 patterns See design patterns subsitution pattern, 582 peek( ) method, 356–357 performance, 801–802 reuse and, 91–94 placement new operators, 437 pointer arithmetic, 722–723 pointers, 718 arrays, 718–720 casting and, 719–720 const keyword, 286–289 dangling, 182, 446, 739 declaring, 26 dereferencing, 26, 719 dynamic memory, 25–29 function pointers, 725–726 threads, 746–748 inheritance and, 225 to members, 727 mental model, 718–719 to methods, 727 non-type template parameters, 679 to references, 275–276 versus references, 71–72, 278–281 references from, 277 references to, 275–276 smart pointers, 28–29, 727–734 auto_ptr, 728 C++ standard library, 446 class writing, 728–734 reference counting, 732–733 shared_ptr, 731–732 stack unwinding and, 396 unique_ptr, 729–731 weak_ptr, 734 p structures, 27 this, 150–151 typedefs, 296–297 variables, 27 polymorphism, 116 exceptions and, 387–388 inheritance, spreadsheet, 236–237 SpreadsheetCell hierarchy, 241–243 POSIX, initializing semaphores, 371 #pragma directive, precedence, ECMAScript, 584 precision numbers, double precision numbers, 10 predicate function callbacks, 533–534 prefix comments, 64 preprocessor directives, 5–6 #define, #endif, #ifdef, #ifndef, #include, includes, #pragma, preprocessor macros, 312–313 printf( ), 345 printing, tuples, 698–699 printVector( ) function, 482 priority_queue container adapter, 501–503 example, 502–503 operations, 501–503 private, superclasses, 259–260 procedures, 316 functions and, 108 process( ) function, 602–603 processValues( ) function, 692 profiling, 813–814 gprof example, 814–822 Visual C++ 2013 example, 822–825 programming generic, 444 multithreaded (See multithreaded programming) 926 bindex.indd 926 11-08-2014 11:26:26 p p p p p p p p p p q q r r r r r r r r r programming design – regex library programming design, 80 importance of, 80–82 programs, employee records sample program, 37–46 promote( ) method, 39 properties, 109 inheritance and, 115 replacing, 115 protected methods, inheritance, 220 public methods, inheritance, 220 pure virtual methods, 238–239 push( ) method, 499 push_back( ) method, 475, 484–485 put( ) method, 349 putback( ) method, 356 , Q queue container adapter example, 499–501 operations, 499 queue container adapter, 498–501 R race conditions, 743–745 random number engine adapter, 447, 615–616 random number engines, 447, 613–615 linear_congruential_engine, 615 Mersenne twister, 615 predefined, 616 subtract_with_carry_engine, 615 random numbers C++ standard library, 447 distribution, 618–621 generating, 612–621 random_device engine, 614–615 random_shuffle( ) function, 460 range specification, 584 range-based for loop, 21–22 ranges destination, 556–557 source, 556 Ratio library, 603–606 rational numbers, 604 raw output methods, 349 raw string literals, 54–55 rbegin( ) method, 629, 658 r-char-sequence, 55 readName( ) function, 354 read-only access, 426–427 realloc( ) function, 713 recursion, templates, 685–689 refactoring, decomposition and, 67 refcall( ) method, 278–279 reference counting smart pointers, 732–733 reference data members, 191–192 const reference data members, 192–193 reference parameters, 279–281 const, 32 references, 29–30 back references, 583, 587 const keyword, 288–289 data members, 276 initializing, 274 modifying, 275 non-type template parameters, 679 parameters, 276–277 parent classes, 232–234 passing objects by, 164–165 passing variables by, 27, 277 from pointers, 277 to pointers, 275–276 versus pointers, 71–72, 278–281 pointers to, 275–276 reference variables, 274–276 return values, 278 rvalue, 281–286 unnamed values, 274 regex library, 588–589 regex_iterator, 593–594 regex_iterator( ), 593–594 regex_match( ), 589–591 regex_replace( ), 596–599 regex_search( ), 592–593 regex_token_iterator( ), 594–596 typedefs, 588–589 927 bindex.indd 927 11-08-2014 11:26:26 regular expressions – rvalue references regular expressions, 445, 581–582 ECMAScript, 582–588 iterators, 588 raw string literals, 587–588 regex library, 588–589 regular expressions library, 575 reinterpret_cast, 299–300 relational operators, 419–420 relationships functional, 119–120 has-a, 113–114, 116–119 hierarchies, 120–121 inheritance, multiple, 121–122 is-a, 114–116, 116=119 mixin classes, 122 not-a, 119–120 remove( ) method, 494 remove-erase-idiom, 482, 561–562 remove_if( ) method, 494 rend( ) method, 629, 658 repeats, greedy, 583 repetition (ECMAScript), 583 replace( ) function, 560–561 replace operations, 583 required functionality, user interface, 136–137 requirements on elements, 468–469 requirements workflow, 788 return by reference, 805 return types lambda expressions, 536–537 operator overloading, 414–415 return values objects as, 173–174 references, 278 returning values, 22–23 reusable code abstraction, 129–130 aggregation, 132 checks and safeguards, 134 class hierarchies, 131 comments, 138 design, 128–129 documentation, 138 ease of use, 139–140 generality, 139–140 generic programming, 316 interfaces, usability, 134–139 separate concepts, 130–132 subsystems, 130–131 templates, 132–134 user interface dependencies, 132 reusable code and, 131 reuse advantages, 88–89 C standard library, 97–98 capabilities, 90–91 categories of available code, 87 disadvantages, 89–90 frameworks, 88 ideas, 87 inheritance and subclasses and, 226–228 WeatherPrediction class, 225–226 libraries, 88 open source, 96–97 licensing, 94 limitations, 90–91 performance and, 91–94 philosophy, 127–128 platform limitations, 94 prototype, 95 stand-alone functions/classes, 87 strategies, 90–95, 127 support, 94 third-party application bundles, 95–96 writing reusable code, 86 reverse( ) functions, 62, 494 reverse iterators, 629–630 reverse_iterator class, 629, 629–630 reversible containers, 658 ring buffers, 835–839 round-robin scheduling with vector, 486–490 RTTI (Run Time Type Information), 268–269 run-time debug mode, 835 runtime_error exception, 380 RUP (Rational Unified Process) of software development, 787–789 rvalue references, 281–286 move assignment operator, 419 928 bindex.indd 928 11-08-2014 11:26:26 s s s s S s s s s s s s s s s s s s S s s s sample programs – Spreadsheet class S sample programs, employee records system, 37–46 scanf( ), 345 scope, resolution, 302–303 scope resolution operator, 147 Scrum, 790–792 search algorithms, 458, 551–553 seek( ) method, 363–365 self-assignment, 186 self-documenting comments, 66 semantics See move semantics semaphores, initializing, 371 sequencing operator, 415 sequential containers, 468 array class, 497–498 deque, 491 forward_list, 495–497 hashmap, 670–671 list, 492–495 adding/removing elements, 492 element access, 492 enrollment, 494–495 forward_list comparison, 95–497 iterators, 492 merge( ) method, 494 remove( ) method, 494 remove_if( ) method, 494 reverse( ) method, 494 size, 492 sort( ) method, 494 special operations, 493–495 unique( ) method, 494 vector, type parameters, 473 set( ) method, 196 set algorithms, 566–569 set associative container, 515–516 setjmp( ), 371 setValue( ) method, 145 SFINAE (Substitution Failure Is Not An Error), 703–705 shallow copying, 180 shared_ptr, 446, 731–732 short variable, 9 short-circuit logic, 18 sizeof( ) function, 49 slicing, 235 smart pointers, 28–29, 727–734 auto_ptr, 728 C++ standard library, 446 classes, writing, 723–734 double deletion and, 732–733 reference cointing, 732–733 shared_ptr, 731–732 stack unwinding and, 396 unique_ptr, 729–731 weak_ptr, 734 smart pointers, writing, 723–734 software, life cycle RUP (Rational Unified Process), 787–789 Spiral Model, 785–787 Stagewise Model, 783 Waterfall Model, 783–785 software design, 80 feature creep, 782 software engineering, 781 Agile Methodology, 789 Scrum, 790–792 XP (Extreme Programming), 792–796 software triage, 796 sort( ) function, 565–566 sort( ) method, 494 sorting algorithms, 462, 565–566 Source Code Control software, 797–799 source files, template definitions, 325 source ranges, 556 spaces in code, 74 specialization function templates, 340–341 partial specialization classes, 679–683 functions, 683–684 splicing, 492 Spreadsheet class definition, 178 Spreadsheet class, 144 assignment operator, 185–187 copy constructors, declaration, 185 929 bindex.indd 929 11-08-2014 11:26:27 SpreadsheetCell – STL (standard template library) SpreadsheetCell, 144 SpreadsheetCell base class, 237–239 SpreadsheetCell class, 144 subclassing, 240 spreadsheets, 144 application example Spreadsheet class, 144 SpreadsheetCell base class, 237–239 SpreadsheetCell class, 144 inheritance and, polymorphism, 236–237 stack, 25 constructors on, 154 objects on, 151 destruction, 169 out of scope, 169 unwinding, 394–397 variables, exceptions, 31 stack arrays, multi-dimensional, 715–716 stack container, 451 stack container adapter example, 504 operations, 504 stack frame, 25 stand-alone, reuse and, 87 stand-alone functions/classes, reuse and, 87 standard library, 36 classes, 36 standard output, 348 start-time debug mode, 831–834 statements catch, 388–389, 404 class definitions, 144 throw, 373 static data members, 188–190 access, 189–190 counters, 189 static keyword data members, 291 functions, 293–294 linkage, 291–292 methods, 291 variables, 293–294 static linkage, 291 static methods, 193–194 overridden methods, 257–258 static_assert macro, 840–841 static_cast, 298–299 std::array, 20 std::bind( ), 546–548 std::call_once( ), 763–764 std::cerr, std::cout, std::endl, std::function, 601–603 function pointers, implementing, 602 std::pair class, 621–624 std::swap( ), 647 std::vector, 36–37 std::vector class, 36–37 STL (standard template library), 94–95, 132, 443 algorithms, 456–458 comparison, 459 heap, 463 modifying, 459–460 non-modifying, 458–459 numerical processing, 464 operational, 461 search algorithms, 458 sorting, 462 utility algorithms, 459 Allocator type, 628 containers, 448–449 array, 450 bitset, 453–454 deque, 450 forward_list, 450 hash tables, 453 list, 450 map, 452–453 multimap, 452 multiset, 452 priority_queue, 451 set, 452 stack, 451–452 table listing, 454–456 unordered associative containers, 453 vector, 449 writing, 636–644 930 bindex.indd 930 11-08-2014 11:26:27 s s s s strcat( ) function – subscripting operator extending, algorithm writing, 634–638 iterator adapters insert iterators, 631–632 move iterators, 632–633 reverse iterators, 629–630 stream iterators, 630–631 iterator traits, 635–636 omissions, 465 vector container, 280–281 strcat( ) function, 49 strcopy( ) function, 48 stream iterators, 630–631 input stream iterator, 630 output stream iterators, 630 streams, 345, 346–347, 524 See also I/O streams buffered, 346 cout, 348 current position, 347 destinations, 347 file streams, 362–363 ifstream destructor, 362 ofstream destructor, 362 seek( ) method, 363–365 tell( ) method, 363–365 fstream class, 367 in-memory, 360–361 input, 353–354 error handling, 357–358 get( ) method, 354–355 getline( ), 357 peek( ), 356–357 putback( ), 356 readName( ) function, 354 unget( ), 355–356 linking, 365–366 output buffered, 349 flush( ) method, 349 put( ) method, 349 write( ) method, 349 sources, 347 string streams, 360–362 unbuffered, 346 writing to, mutex classes, 764–765 string class, 51–53, 445 numeric conversion, 53–54 operators, 51–53 string literals, 50 const characters, 50 localizing, 576 raw string literals, 587–588 string streams, 360–362 string type, 30 strings, 445, 524 C-style, 30 dynamic C-style strings, 48–50 raw string literals, 54–55 string class, 51–53 string literals, 50 nonstandard, 30 numeric conversions, 53–54 underallocating, 734–735 wide characters, 576–577 StringSpreadsheetCell, 239 StringSpreadsheetCell class, 239 stringstream class, 367 stringToDouble( ) method, 193 strlen( ) function, 49 strongly typed enumerations, 14–15 Stroustrup, Bjarne, structs, 15, 146 structures, pointers to, 27 subclasses copy constructors, 264–265 equals operator, 264–265 inheritance, reuse and, 226–228 parent classes, parent constructors, 229–230 protected methods, 220 public methods, 220 replacing functionality, 228 SpreadsheetCell class, 240 subclassing, 114 SubObject class, 403–404 subscripting operator, 423–428 non-integral array indices, 427–428 read-only access, 426–427 931 bindex.indd 931 11-08-2014 11:26:27 substitution pattern – thread pools substitution pattern, 582 subsystems, code reuse and, 130–131 subtraction operator (-), 12 subtract_with_carry_engine, 615 superclasses, 115 abstract, 115 inheritance, 218 methods access level, 261–263 arguments, 260–261 private, 259–260 swap( ) function, 482, 647 switch statements, 16–17 symbolic debugger, 843 system_clock, 610 T tabs in code, 74 tell( ) method, 363–365 template classes, writing, 317–324 template metaprogramming factorials at compile time, 696 loop unrolling, 696–697 tuple printing, 698–699 type traits, 699–702 template specializations, 334–336 inheritance comparison, 337 template template parameters, 676–678 template types, 343 templates, 316, 444 aliases, 338 benefits, 133 class templates, 317 friend function templates, 342–343 partial specialization, 679–683 classes, subclassing, 336–337 code reuse, 132–134 coding without, 317–320 cons, 133 function templates, 339–343 overloading, 341–342 specialization, 340–341 generic programming, 444 generic template class, 133 grid class, 320–322 hashmap class, 637–638 header files, 325–326 inheritance comparison, 133–134 instantiation, 321 selective, 325 iterator template arguments, 551 keywords auto, 689–691 decltype, 689–691 make_pair( ), 505 method templates, 330–334 names, 321 NGrid template class, 686–689 parameterization, 316 parameters integer non-type parameters, 327–329 non-type, 327–329, 678–679 parameter packs, 694 type, 674–676 processing, 325 recursion, 685–689 source files, 326 templated types (regex library), 588 types, 325693 zero-initialization, 328–333 variadic, 691–695 mixin classes, 694–695 type-safe variable-length argument lists, 692–694 writing, 317–324 ternary operators, 11, 17 test workflow, 788 testCallback( ) function, 541 The C++ Programming Language (Bjarne), The C Programming Language (Kernighan and Ritchie), third-party applications, bundling, reuse and, 95–96 this pointer, 150–151 thread pools, 776–777 932 bindex.indd 932 11-08-2014 11:26:27 t t t t t t t t t t t t t t t t t t t threadFunc( ) function – unordered_multiset associative container threadFunc( ) function, 753 threading design, 777–778 library, 901 models, 101 threads cancelling, 752 function objects, 748–750 function pointers, 746–748 lambda expression, 750 member functions, 751 results retrieval, 752 throw keyword, 374 throw lists, 382–387 usefulness, 386–387 throw statement, 373 throwing exceptions multiple, 378–380 stack unwinding and, 396–397 time_point class, 610, 611–612 time_point type, 610 tokenizing values, 353 try/catch construct, 373 tuples, 447, 621–624 printing, 698–699 type inference auto keyword, 24 decltype keyword, 689–691 type parameters, templates, 674–676 type traits, 699–702 typedefs, 295–296 associative containers, 658–659 container requirements, 648 function pointers, 296–297 hashmap class, 648–649 iterators, 472–473, 655–656 regex library, 588–589 typeid operator, virtual methods, 268 typename keyword, 641 types, 316 aliases, 297 atomic types, 755–757 categories, 699–702 covariant return types, 249 enumerated, 13–14 classes, 201 strongly typed enumerations, 14–15 operator overloading and, 211 overridden methods, 249–250 relations, 702–703 string, 30 structs, 15 templates, 325 type-safe enumerations, 14–15 type-safe variable-length argument lists, 692–694 U UCS (Universal Character Set), 577 unary operators, 11 overloading, 420 unbuffered streams, 346 unexpected( ) function, 384 unexpected_handler, 384 unget( ) method, 355–356 uniform initialization, 476 uniform random number generator, 447 uninitialized pointers, derefencing, 27 unions, 146 unique( ) function, 494, 562 unique_ptr, 446, 729–731 unit testing sample data, 912–913 unordered associative containers, 453, 516–522, 636–644 See also hash tables unordered_map, 519–521 example, 521–522 map comparison, 519–520 unordered_multimap, 522 unordered_multiset, 522 unordered_set, 522 unordered_map associative container, 519–521 example, 521–522 map comparison, 519–520 unordered_multimap associative container, 522 unordered_multiset associative container, 522 933 bindex.indd 933 11-08-2014 11:26:28 unordered_set associative container – vector unordered_set associative container, 522 unsigned int variable, unsigned long long variable, unsigned long variable, unsigned short variable, unwinding stack, 394–397 upcasting, 235 ambiguities and, 247 upper_bound( ) function, 566 user interface, dependencies, code reuse and, 132 user-defined, vectors, 476 user-defined classes, vectors, 476 user-defined literals (C++11), 307–309 using directive, using keyword, 253 utilities mathematical, 446–447 time, 447 utility algorithms, 459, 555–556 utiltities, variable-length argument lists, 310–312 V valarray class, 446 value semantics, 468–469 values, 316 parameterizing, 316 passing by, 277 disallowing, 188 passing variables by, 27 return values, references, 278 returning, 22–23 variable-length argument lists, 310–312 variables, bool, 10 casting, 10 char, 10 char16_t, 10 char32_t, 10 coercing, 10 condition variables, 767–769 const keyword, 287 converting, 10 declaring, double, 10 float, 10 int, 10 long, 10 long double, 10 long long, 10 nonlocal, order of initialization, 294 passing by reference, 27, 277 by value, 27 by values, 277 pointers, 27 reference variables, 274–276 short, 10 stack, exceptions, 31 static, 293–294 string literals, 50 type changing, 10 unsigned int, 10 unsigned long, 10 unsigned long long, 10 unsigned short, 10 wchar_t, 10 variadic templates, 691–695 mixin classes, 694–695 ring buffer and, 835–839 type-safe variable-length argument lists, 692–694 vector, 283 assigning, 476–477 built-in classes, 476 comparing, 477 constructors, 475–476 copying, 476–477 destructors, 75–476 dynamic-length, 475 elements access methods, 474–475 appending, 481–485 initial value, 474–475 user-defined classes, 476 fixed-length, 474–475 heap, allocation, 476 intVector, 476–477 934 bindex.indd 934 11-08-2014 11:26:28 v v v v v v vector – zero-initialization iterators, 478–481 memory allocation scheme, 485–486 printVector( ) function, 482 push_back( ) method, 372 round-robin scheduling, 486–490 vector, 490–491 vector type parameters, 473 vector container, 280–281, 449–450 virtual base classes, 248, 270–271 virtual destructors, 232 method templates, 330 need for, 267–268 virtual keyword, 222 implementing, 266–267 justification for, 267 virtual methods, 222 method templates, 330 overriding, 265–266 pure, 238–239 typeid operator, 268 Visual C++ 2010 debugger, 859–861 voter registration auditing algorithm example, 570–573 W wait( ) method, 768 wchar_t variable, 10 weak_ptr, 734 WeatherPrediction class, 225–228 MyWeatherPrediction class, 225–228 what( ) method overriding, 340 Windows, memory leaks, 737–738 word boundaries, 586 workflows, 788 write( ) method, 349 X-Y-Z zero-initialization, 476 935 bindex.indd 935 11-08-2014 11:26:28 badvert.indd 936 11-08-2014 11:25:27 Related Wrox Books Beginning ASP.NET 4.5.1 Programmer to Programmer™ Connect with Wrox ISBN: 978-1-118-84677-3 Beginning ASP.NET 4.5.1 guides you through the process of creating a fully functional, database-driven website, from creation of the most basic site structure all the way down to the successful deployment of the website to a production environment Best-selling author Imar Spaanjaars provides a firm foundation for coders new to ASP.NET and key insights for those not yet familiar with the important updates in the 4.5.1 release Ivor Horton’s Beginning Visual C++ 2013 ISBN: 978-1-118-84571-4 This guide delivers a comprehensive introduction to both the standard C++ language and Visual C++ 2013 Step-by-step programming exercises, helpful examples, and clear solutions deftly walk you through the ins and outs of the latest C++ development Professional C# 5.0 and NET 4.5.1 Participate User Group Program Take an active role online by participating in our P2P forums @ p2p.wrox.com Become a member and take advantage of all the benefits Wrox Blox Wrox on Download short informational pieces and code to keep you up to date and out of trouble Follow @wrox on Twitter and be in the know on the latest news in the world of Wrox Join the Community Wrox on Sign up for our free monthly newsletter at newsletter.wrox.com Join the Wrox Facebook page at facebook.com/wroxpress and get updates on new books and publications as well as upcoming programmer conferences and user group events Wrox.com Browse the vast selection of Wrox titles, e-books, and blogs and find exactly what you need Contact Us We love feedback! Have a book idea? Need community support? Let us know by e-mailing wrox-partnerwithus@wrox.com ISBN: 978-1-118-83303-2 Written by a dream team of NET experts, this book includes everything developers need to work with C#, the language of choice for NET applications Professional C# 5.0 and NET 4.5.1 is perfect for both experienced C# programmers looking to sharpen their skills and professional developers who are using C# for the first time Professional Visual Studio 2013 ISBN: 978-1-118-83204-2 This comprehensive guide provides a complete view of the new and updated tools featured in Visual Studio 2013 that make programming easier and more efficient Topics include new shortcuts, UI testing capabilities, and customization options, along with changes to target SharePoint 2013, advanced debugging capabilities, the Data Compare function, and a host of others Professional Application Lifecycle Management with Visual Studio 2013 ISBN: 978-1-118-83658-3 Microsoft’s Application Lifecycle Management (ALM) makes software development easier and now features support for iOS, MacOS, Android, and Java development Microsoft’s ALM suite of productivity tools includes new functionality and extensibility that are sure to grab your attention Professional Application Lifecycle Management with Visual Studio 2013 provides in-depth coverage of these new capabilities Related Wrox Books Beginning ASP.NET 4.5.1 Programmer to Programmer™ Connect with Wrox ISBN: 978-1-118-84677-3 Beginning ASP.NET 4.5.1 guides you through the process of creating a fully functional, database-driven website, from creation of the most basic site structure all the way down to the successful deployment of the website to a production environment Best-selling author Imar Spaanjaars provides a firm foundation for coders new to ASP.NET and key insights for those not yet familiar with the important updates in the 4.5.1 release Ivor Horton’s Beginning Visual C++ 2013 ISBN: 978-1-118-84571-4 This guide delivers a comprehensive introduction to both the standard C++ language and Visual C++ 2013 Step-by-step programming exercises, helpful examples, and clear solutions deftly walk you through the ins and outs of the latest C++ development Professional C# 5.0 and NET 4.5.1 Participate User Group Program Take an active role online by participating in our P2P forums @ p2p.wrox.com Become a member and take advantage of all the benefits Wrox Blox Wrox on Download short informational pieces and code to keep you up to date and out of trouble Follow @wrox on Twitter and be in the know on the latest news in the world of Wrox Join the Community Wrox on Sign up for our free monthly newsletter at newsletter.wrox.com Join the Wrox Facebook page at facebook.com/wroxpress and get updates on new books and publications as well as upcoming programmer conferences and user group events Wrox.com Browse the vast selection of Wrox titles, e-books, and blogs and find exactly what you need Contact Us We love feedback! Have a book idea? Need community support? Let us know by e-mailing wrox-partnerwithus@wrox.com ISBN: 978-1-118-83303-2 Written by a dream team of NET experts, this book includes everything developers need to work with C#, the language of choice for NET applications Professional C# 5.0 and NET 4.5.1 is perfect for both experienced C# programmers looking to sharpen their skills and professional developers who are using C# for the first time Professional Visual Studio 2013 ISBN: 978-1-118-83204-2 This comprehensive guide provides a complete view of the new and updated tools featured in Visual Studio 2013 that make programming easier and more efficient Topics include new shortcuts, UI testing capabilities, and customization options, along with changes to target SharePoint 2013, advanced debugging capabilities, the Data Compare function, and a host of others Professional Application Lifecycle Management with Visual Studio 2013 ISBN: 978-1-118-83658-3 Microsoft’s Application Lifecycle Management (ALM) makes software development easier and now features support for iOS, MacOS, Android, and Java development Microsoft’s ALM suite of productivity tools includes new functionality and extensibility that are sure to grab your attention Professional Application Lifecycle Management with Visual Studio 2013 provides in-depth coverage of these new capabilities WILEY END USER LICENSE AGREEMENT Go to www.wiley.com/go/eula to access Wiley’s ebook EULA ffirs.indd 13 11-08-2014 11:29:09 ... 11-08-2014 11:29:07 Professional C++ ffirs.indd 11-08-2014 11:29:07 ffirs.indd 11-08-2014 11:29:07 PROFESSIONAL C++ Third Edition Marc Gregoire ffirs.indd 11-08-2014 11:29:08 Professional C++, Third Edition... Part II: PROFESSIONAL C++ SOFTWARE DESIGN CHAPTER 4: DESIGNING PROFESSIONAL C++ PROGRAMS What Is Programming Design? The Importance of Programming Design Designing for C++ Two Rules for C++ Design... 11-08-2014 11:29:09 PROFESSIONAL C++ INTRODUCTION xli ➤➤PART I INTRODUCTION TO PROFESSIONAL C++ CHAPTER A Crash Course in C++ and the STL

Ngày đăng: 09/11/2019, 00:50

Từ khóa liên quan

Mục lục

  • Professional C++

  • Copyright

  • Contents

  • Introduction

    • Who This Book Is For

    • What This Book Covers

    • How This Book Is Structured

    • What You Need to Use This Book

      • Microsoft Visual C++

      • GCC

      • Conventions

      • Source Code

      • Errata

      • P2P.Wrox.Com

      • Part I: Introduction to Professional C++

        • Chapter 1: A Crash Course in C++ and the STL

          • The Basics of C++

            • The Obligatory Hello, World

            • Namespaces

            • Variables

            • Literals

            • Operators

            • Types

            • Conditionals

            • Arrays

Tài liệu cùng người dùng

Tài liệu liên quan