Wiley
Wiley.com
Print this page Share

Professional C++, 2nd Edition

ISBN: 978-0-470-93244-5
1104 pages
October 2011
Professional C++, 2nd Edition (0470932449) cover image
Essential reading for experienced developers who are determined to master the latest release of C++

Although C++ is often the language of choice from game programming to major commercial software applications, it is also one of the most difficult to master. With this no-nonsense book, you will learn to conquer the latest release of C++. The author deciphers little-known features of C++, shares detailed code examples that you can then plug into your own code, and reveals the significant changes to C++ that accompany the latest release. You'll discover how to design and build applications that solve real-world problems and then implement the solution using the full capabilities of the language.

Appeals to experienced developers who are looking for a higher level of learning

  • Drills down the extensive changes to the latest C++ standard, C++11, including enhancements made to run-time performance, standard library, language usability, and core language
  • Zeroes in on explaining the more poorly understood elements of the C++ feature set and addresses common pitfalls to avoid
  • Includes case studies that feature extensive, working code that has been tested on Windows and Linux platforms
  • Intertwines text with useful tips, tricks, and workarounds

Packed with best practices for programming, testing, and debugging applications, this book is vital for taking your C++ skills to the next level.

See More
INTRODUCTION xxv

PART I: INTRODUCTION TO PROFESSIONAL C++

CHAPTER 1: A CRASH COURSE IN C++ 3

CHAPTER 2: DESIGNING PROFESSIONAL C++ PROGRAMS 49

CHAPTER 3: DESIGNING WITH OBJECTS 77

CHAPTER 4: DESIGNING FOR REUSE 97

CHAPTER 5: CODING WITH STYLE 111

PART II: C++ CODING THE PROFESSIONAL WAY

CHAPTER 6: GAINING PROFICIENCY WITH CLASSES AND OBJECTS 133

CHAPTER 7: MASTERING CLASSES AND OBJECTS 169

CHAPTER 8: DISCOVERING INHERITANCE TECHNIQUES 211

CHAPTER 9: UNDERSTANDING C++ QUIRKS AND ODDITIES 267

CHAPTER 10: HANDLING ERRORS 317

CHAPTER 11: DELVING INTO THE STANDARD LIBRARY 361

CHAPTER 12: UNDERSTANDING CONTAINERS AND ITERATORS 385

CHAPTER 13: MASTERING STL ALGORITHMS 457

CHAPTER 14: USING STRINGS AND REGULAR EXPRESSIONS 509

CHAPTER 15: DEMYSTIFYING C++ I/O 545

CHAPTER 16: ADDITIONAL LIBRARY UTILITIES 569

CHAPTER 17: CUSTOMIZING AND EXTENDING THE STL 595

PART III: MASTERING ADVANCED FEATURES OF C++

CHAPTER 18: OVERLOADING C++ OPERATORS 645

CHAPTER 19: WRITING GENERIC CODE WITH TEMPLATES 683

CHAPTER 20: ADVANCED TEMPLATES 715

CHAPTER 21: EFFECTIVE MEMORY MANAGEMENT 759

CHAPTER 22: MULTITHREADED PROGRAMMING WITH C++ 797

PART IV: C++ SOFTWARE ENGINEERING

CHAPTER 23: MAXIMIZING SOFTWARE ENGINEERING METHODS 839

CHAPTER 24: WRITING EFFICIENT C++ 859

CHAPTER 25: DEVELOPING CROSS-PLATFORM AND CROSS-LANGUAGE APPLICATIONS 883

CHAPTER 26: BECOMING ADEPT AT TESTING 905

CHAPTER 27: CONQUERING DEBUGGING 927

CHAPTER 28: INCORPORATING DESIGN TECHNIQUES AND FRAMEWORKS 967

CHAPTER 29: APPLYING DESIGN PATTERNS 985

APPENDIX A: C++ INTERVIEWS 1013

APPENDIX B: ANNOTATED BIBLIOGRAPHY 1035

APPENDIX C: STANDARD LIBRARY HEADER FILES 1045

INDEX 1053

See More
Marc Gregoire is a Microsoft Visual C++ MVP, an active contributor to CodeGuru, and blogs at www.nuonsoft.com/blog/. Marc is a software architect, worked for Siemens and Nokia Siemens Networks as a software consultant, and now works for Nikon Metrology.

Nicholas A. Solter is an application architect at ContextOptional, Inc., a social media advertising company.

Scott J. Kleper is cofounder and CTO of ContextOptional, Inc.

See More
Download TitleSizeDownload
Bonus Chapter 1 2.04 MB Click to Download
Bonus Chapter 2 772.61 KB Click to Download
ReadMe File 3.88 KB Click to Download
Full Code Download
Updated 10/28/11 wit new std_array.cpp file for Chapter 1. Gameboard (in Chapter 19) was updated on 8/2/12.
912.17 KB Click to Download
Chapter 1
std_array.cpp updated 10/28/11
13.14 KB Click to Download
std_array.cpp
This CPP file replaces the one in the code archive for Chapter 1 (932445c01_code/std_array/std_array.cpp). It contains the below fix for page 22: #include #include using namespace std; int main() { array arr = {9, 8, 7}; cout << "Array size = " << arr.size() << endl; for (auto i : arr) cout << i << endl; return 0; }
242 bytes Click to Download
Chapter 6 20.07 KB Click to Download
Chapter 7 30.81 KB Click to Download
Chapter 8 10.44 KB Click to Download
Chapter 9 19.64 KB Click to Download
Chapter 10 25.79 KB Click to Download
Chapter 11 2.34 KB Click to Download
Chapter 12 36.96 KB Click to Download
Chapter 13 27.45 KB Click to Download
Chapter 14 9.04 KB Click to Download
Chapter 15 11.50 KB Click to Download
Chapter 16 9.80 KB Click to Download
Chapter 17 14.98 KB Click to Download
Chapter 18 18.24 KB Click to Download
Chapter 19
The Gameboard file was updated on 8/2/12.
25.42 KB Click to Download
Chapter 20 25.01 KB Click to Download
Chapter 21 9.27 KB Click to Download
Chapter 22 14.07 KB Click to Download
Chapter 24 42.58 KB Click to Download
Chapter 25 5.09 KB Click to Download
Chapter 26 3.87 KB Click to Download
Chapter 27 22.88 KB Click to Download
Chapter 28 5.71 KB Click to Download
Chapter 29 11.00 KB Click to Download
Gameboard (for Chapter 19)
Updated Gameboard code on 8/2/12.
1.70 KB Click to Download
See More

Do you think you've discovered an error in this book? Please check the list of errata below to see if we've already addressed the error. If not, please submit the error via our Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
xiii, 258 Error in Text
Currently reads:
Copy Constructors and the Equals Operator in Subclasses

Should read:
Copy Constructors and the Assignment Operator in Subclasses
06/04/2012
22 Error in Code
Reads:
#include <iostream>
#include <array>
using namespace std;
int main()
{
                array<int, 3> arr = {9, 8, 7};
                cout << "Array size = " << arr.size() << endl;
                for (auto i : arr)
                                cout << i << endl;
                                cout << *iter << endl;

                return 0;
}

Should be:
#include <iostream>
#include <array>
using namespace std;
int main()
{
                array<int, 3> arr = {9, 8, 7};
                cout << "Array size = " << arr.size() << endl;
                for (auto i : arr)
                                cout << i << endl;

                return 0;
}


10/26/2011
28 Error in Code
Currently reads:
char* pointerString = "Hello, World";

Should read:
const char* pointerString = "Hello, World";
06/04/2012
232 Error in Text
The sentence:
?No code needs to be written in the .cpp file, and any attempt to write code will cause a compiler error.?

Should become:
?No code needs to be written in the .cpp file.?
08/17/2012
390 Error in Text
The first sentence on this page says:
"The standard containers that provide iterators all furnish either random access or bidirectional iterators."

This is untrue and should be deleted.
06/04/2012
414 Error in Text
Sentence in second paragraph currently reads:
"A list supports begin(), returning an iterator referring to the first element in the list, and end(), returning an iterator referring to the last element in the list."

Sentence should read:
"A list supports begin(), returning an iterator referring to the first element in the list, and end(), returning an iterator referring to one past the last element in the list."
06/04/2012
468 Error in Code
Code currently reads:
int cnt = count_if(vec.cbegin(),vec.cend(),
[=, &cntLambdaCalled](int i){++cntLambdaCalled; return i>value;});


Code should read:
int cnt = count_if(vec.cbegin(),vec.cend(),
                     [=, &cntLambdaCalled](int i)->bool{++cntLambdaCalled; return i>value;});
06/04/2012
487 Error in Text
The description of lexicographical_compare() currently reads:
lexicographical_compare() deals with the situation where the two ranges may contain different numbers of elements. It returns true if all the elements in the first range are less than their corresponding elements in the second range, or, if the first range has fewer elements than the second and all elements in the first range are less than their corresponding initial subsequence in the second set.

This should read:
"... It returns true if the first unequal element in the first range is less than its corresponding element in the second range, or, if the first range has fewer elements than the second and all elements in the first range are equal to their corresponding initial subsequence in the second set."
06/04/2012
596 Error in Text
Currently reads:
"This regular expression searches for spaces, newlines, form feeds, and back slashes."

Should read:
"... newlines, carriage returns, and back slashes."
06/04/2012
596 Error in Text
Currently reads:
"Every reversible container in the STL, which happens to be every container that's part of the standard, ..."

Should read:
"Every reversible container in the STL, which happens to be every container that's part of the standard, ...except forward_list and the unordered associative containers".
06/04/2012
685 Error in Code
Please replace current code Gameboard.H with:
class GameBoard
{
public:
       // The general-purpose GameBoard allows the user to specify its dimensions
       GameBoard(size_t inWidth = kDefaultWidth, size_t inHeight = kDefaultHeight);
       GameBoard(const GameBoard& src); // copy constructor
       virtual ~GameBoard();
       GameBoard& operator=(const GameBoard& rhs); // assignment operator

       void setPieceAt(size_t x, size_t y, const GamePiece* inPiece);
       GamePiece* getPieceAt(size_t x, size_t y);
       const GamePiece* getPieceAt(size_t x, size_t y) const;

       size_t getHeight() const { return mHeight; }
       size_t getWidth() const { return mWidth; }
       static const size_t kDefaultWidth = 10;
       static const size_t kDefaultHeight = 10;

protected:
       void copyFrom(const GameBoard& src);
       void initializeCells();
       void cleanupCells();
       // objects dynamically allocate space for the game pieces.
       GamePiece*** mCells;
       size_t mWidth, mHeight;
};
06/04/2012
685 Error in Text
The last paragraph currently reading:
...?getPieceAt() returns a reference to the piece?? and ends with ??before using the returned reference.?

This should be deleted.
06/04/2012
686 Error in Text
The note at the top of the page currently reads:
"This implementation of the class provides two versions of getPieceAt(), one of which returns a reference and one of which returns a const reference."

This should should be deleted.
06/04/2012
686-687 Error in Code
The code on pages 686-687 (Gameboard.cpp) should be deleted and replaced with the following:

GameBoard::GameBoard(size_t inWidth, size_t inHeight) :
  mWidth(inWidth), mHeight(inHeight)
{
  initializeCells();
}
GameBoard::GameBoard(const GameBoard& src)
{
  copyFrom(src);
}
GameBoard::~GameBoard()
{
  // free the old memory
  cleanupCells();
}
void GameBoard::copyFrom(const GameBoard& src)
{
  mWidth = src.mWidth;
  mHeight = src.mHeight;

  initializeCells();

  for (size_t i = 0; i < mWidth; i++) {
    for (size_t j = 0; j < mHeight; j++) {
      if (src.mCells[i][j])
        mCells[i][j] = src.mCells[i][j]->Clone();
    }
  }
}
void GameBoard::initializeCells()
{
  mCells = new GamePiece** [mWidth];
  for (size_t i = 0; i < mWidth; i++) {
    mCells[i] = new GamePiece*[mHeight];
    for (size_t j = 0; j < mHeight; j++) {
      mCells[i][j] = nullptr;
    }
  }
}
void GameBoard::cleanupCells()
{
  for (size_t i = 0; i < mWidth; i++) {
    for (size_t j = 0; j < mHeight; j++) {
      delete mCells[i][j];
    }
    delete [] mCells[i];
  }
  delete [] mCells;
  mCells = nullptr;
}
GameBoard& GameBoard::operator=(const GameBoard& rhs)
{
  // check for self-assignment
  if (this == &rhs) {
    return *this;
  }
  // free the old memory
  cleanupCells();
  // copy the new memory
  copyFrom(rhs);
  return *this;
}
void GameBoard::setPieceAt(size_t x, size_t y, const GamePiece* inElem)
{
  if (inElem)
    mCells[x][y] = inElem->Clone();
}
GamePiece* GameBoard::getPieceAt(size_t x, size_t y)
{
  return mCells[x][y];
}
const GamePiece* GameBoard::getPieceAt(size_t x, size_t y) const
{
  return mCells[x][y];
}



06/04/2012
687 Error in Code
Currently reads:
GameBoard chessBoard(8, 8);
ChessPiece pawn;
chessBoard.setPieceAt(0, 0, pawn);


Should read:
GameBoard chessBoard(8, 8);
ChessPiece pawn;
chessBoard.setPieceAt(0, 0, &pawn);

06/04/2012
689 Error in Text
Text currently reads:
?mCells is now a T** instead of a GamePiece** because??

Should read:
?mCells is now a T** instead of a GamePiece*** because??
06/04/2012
803-804 Error in Text
Currently reads: 10.000 and 100.000

Should read: 10,000 and 100,000.
06/10/2013
1053 Error in text
Currently reads:
- - decrement operator, 11

Should read:
-- decrement operator, 11 (space between symbols)
04/25/2012
See More

Related Titles

Back to Top