Home > Store

INFORMIT C++ Reference Guide

Register your product to gain access to bonus material or receive a coupon.

INFORMIT C++ Reference Guide

Custom Published Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2006
  • Dimensions: 7.375 x 9.25
  • Pages: 600
  • Edition: 1st
  • Custom Published Book
  • ISBN-10: 0-536-94146-7
  • ISBN-13: 978-0-536-94146-6

Informit.com brings its online reference guides to print!

Started several years ago as on online document for those who wanted to know more about C++, the Informit C++ Reference Guide grew into a rich repository of insights, advice, and great resources for every programmer. At the request of many readers, we’ve created this convenient print version.

The Informit C++ Reference Guide offers the fundamentals of C++ knowledge, as well as essays, commentaries, and opinions that make it much more that your basic introduction to C++. The first 15 chapters contain the mandatory C++ knowledge base -- what every C++ programmer should know. These topics include the Special Member Functions, Operator Overloading, Memory Management, Templates, Object-Oriented Programming and Design, the Standard Library, to name a few.

The C++ Reference Guide has always been much more than an online C++ tutorial, though. The ability to react on a weekly basis to new developments in the C++ and IT arenas has turned it into an ongoing dialog with the latest trends and emerging technologies. Therefore, this book is also a collection of essays, commentaries and excursions about various topics that aren't necessarily confined to pure C++ programming. Chapter 16, "A Tour of C99" presents the recent changes in standard C, (some of which are currently being integrated into C++ as well). Chapter 17, "Dynamic Linking", discusses the probable standardization of a dynamic linking interface and demonstrates how POSIX and Windows implement this feature. Chapter 18, "Tips and Techniques", which is the largest chapter in this book, contains dozens of "how do I?" style recipes for solving common programming tasks, as well as short essays about miscellaneous topics: migrating to 64-bit platforms, complex arithmetic, the C++ object model, const declarations, and many others. Chapter 19, "Design Patterns" is dedicated to Patterns and Pattern-related topics: Anti-patterns and Refactoring. Chapter 20, "C++0X: The New Face of Standard C++" presents some of the latest additions to standard C++, including TR1's library and the reference wrapper family of classes. Finally, chapter 21, "The Reflecting Circle", is the most philosophical chapter in this book. Here you will find a discussion about the future of programming, a brief tutorial to digital sound compression formats, and even an introduction to Aspect-Oriented-Programming.

This book summarizes more than two years of C++ writing. Whether you're a beginner or a seasoned C++ programmer, this convenient and portable format will serve you well in your everyday design and programming engagements.

Sample Content

Downloadable Sample Chapter

Download the sample chapter for this title.

Table of Contents

 

CONTENTS

Chapter 1  What Is C++?      1

C++ as “Better C”      1

The Structure of a C++ Program      3

Overloading      4

Support for Object-Oriented Programming      6

Generic Programming      6

InformIT Articles and Sample Chapters      7

Books and e-Books      8

Official Documentation      9

Chapter 2  Special Member Functions: Constructors, Destructors, and the Assignment Operator      11

Constructors      11

Trivial Constructors      13

Pseudo-Constructors of Built-in Types      13

explicit Constructors      14

Constructor Categories      14

The explicit Keyword      16

Advice      16

Member Initialization Lists      17

Copy Constructor      20

Assignment Operator      21

Destructors      22

Explicit Destructor Invocation      22

Summary      23

InformIT Articles and Sample Chapters      23

Books and e-Books      24

Online Resources      24

Chapter 3  Operator Overloading      25

Operator Overloading Guidelines      26

Returning Objects by Value      29

Overloading and User-Defined Types      30

Conversion Operators      32

Summary      33

Books and e-Books      34

Online Resources      34

Chapter 4  Memory Management      35

Automatic Storage      35

Static Storage      36

The Free Store      36

POD (Plain Old Data) and Non—POD Objects      37

malloc() and free() Versus new and delete      38

Support for Object Semantics      38

Safety      39

Allocating and Deallocating Arrays Using new[] and delete[]      39

Dealing with Exceptions      40

Placement new      41

Allocation Strategies      42

Using Placement new       42

Explicit Destructor Invocation      44

Cleanup      44

Summary      44

Online Books      45

Articles      45

nothrow new      46

A Bit of History      46

Standard-Compliant new      46

nothrow new’s Interface      47

Putting nothrow new to Work      48

Summary      48

Member Alignment      49

Overriding new and delete      49

Declaring new and delete as Class Members      50

Implementation      50

Additional Customizations      51

Usage of new and delete      51

Overriding new and delete Globally      52

Using Class auto_ptr to Automate Memory Management      53

Exceptions and Dynamic Memory Allocation      54

Introducing std:: auto_ptr      54

Using std::auto_ptr      56

auto_ptr Caveats      56

Summary      57

Linkage Types      57

Guidelines for Effective Memory Management      59

Preferring Automatic Storage to Free Store      59

Instantiating a Local Object      61

Zero Initialization      61

Deleting Pointers      63

Summary      64

InformIT Articles and Sample Chapters      64

Online Resources      65

Chapter 5  Templates      67

Class Templates      67

Declaring a Class Template      67

Instantiation and Specialization      69

Template Arguments      71

Default Type Arguments      72

Template Specializations      72

Defining a Primary Template      73

Defining a Specialization      74

Partial Specializations      75

Explicit Specialization of a Class Template      75

Function Templates      77

exported Templates      77

The Separate Compilation Model      77

export–How It All Began      78

State of the Art      78

Which Compilers Support export?      78

export and User Expectations      79

Future Directions      80

Conclusions      80

Books      80

Summary      81

InformIT Articles and Sample Chapters      81

Books and e-Books      82

Online Resources      82

Chapter 6  Namespaces      83

Applications of Namespaces      83

Properties of Namespaces      84

Fully Qualified Names      84

using-Declarations and using-Directives      85

Namespace Aliases      86

Argument-Dependent Lookup      86

Using and Extending Namespaces      88

Namespace Members      88

Extending a Namespace      89

Referring to a Namespace Member      91

Interaction with Other Language Features      91

Using the Scope Resolution Operator      91

Using static to Indicate Internal Linkage      92

The Naming Convention of Standard Header Files      92

Summary      93

Online Resources      94

Chapter 7  Time and Date Library      95

Retrieving the Current Time      95

Time Differences and Time Zones      97

Summary      98

Online Resources      98

Chapter 8  Streams      99

Standard C++ Stream Objects      99

Format Flags      101

Extending <iostream> to Support User-Defined Types      102

Supporting Built-In and Standard Types      102

Overloading cout’s <<      103

Overloading cin’s <<      105

Summary      105

String Streams      106

File Streams      106

Summary      107

Online Resources      108

Chapter 9  Object-Oriented Programming and Design Principles      109

Abstract Datatyping      110

Information Hiding      110

Encapsulation      111

Inheritance      112

Polymorphism      114

Dynamic Binding      115

Summary      117

The Rise and Fall of Object Orientation      118

Traditional Object-Oriented Concepts      118

Code Reuse      119

Member Functions      119

Inheritance      120

Conclusions      120

InformIT Articles and Sample Chapters      121

Online Resources      121

Chapter 10  The Standard Template Library (STL) and Generic Programming      123

Principles of Generic Programming      123

Organization of STL Header Files      124

Containers      125

The vector Container Class      125

capacity() and size()      127

Accessing Elements      128

Front and Back Operations      129

The queue Container Class      129

Iterators, Part I      130

Pointers as Iterators      130

Iterators in STL      131

Iterator Categories      132

Input Iterators      133

Output Iterators      133

Using Container Iterators      133

Summary      135

Iterators, Part II      135

Bidirectional Iterators      135

Reverse Iterators      137

Random-Access Iterators      137

Iterator Functions      139

Summary      139

The std::list Container Class      139

Creating a List Object      139

Dealing with Sequences      140

Choosing the Right Container, Part I      141

vector      142

Ayes      142

Nays      142

list      142

Ayes      143

Nays      143

deque      143

Adaptors      143

stack      144

queue      144

Summary      144

Choosing the Right Container, Part II      144

Container Reallocation      144

Capacity Versus Size      146

Invalidation of list Iterators      147

Invalidation of deque Iterators      147

Summary      148

Choosing the Right Container, Part III      148

Fundamentals of Associative Containers      148

Unique Keys Versus Non-Unique Keys      149

Pairs      149

map      149

multimap      150

Searching a multimap      151

set      151

multiset      151

Summary      152

Support for User-Defined Types      152

Algorithms      153

find()      153

copy()      154

sort()      154

Function Objects      155

Uses of Function Objects      156

Predicate Objects      157

Adaptors      158

Specialized Containers      158

Associative Containers      159

Class auto_ptr      160

Class string      160

Constructors      161

Conversion to a C-String      161

Accessing Elements      161

Clearing a string      162

string Comparison      162

String Manipulation      163

Case-Insensitive Comparison      163

Finding a String Within a String      164

Substring Replacement      165

Wonder of Wonders      165

Summary      166

InformIT Articles and Sample Chapters      166

Books and e-Books      167

Online Resources      167

Chapter 11  Exception Handling      169

Traditional Error-Handling Methods      169

Exception-Handling Constructs      170

Stack Unwinding      171

Passing Exception Objects to a Handler      172

Exception Type Match      172

Exception Objects      173

Exception Specifications      173

The Problem      174

Exception Specifications Basics      174

Exception Specifications and Inheritance      175

Empty Exception Specifications and Missing Exception Specifications      176

Exception Specification Enforcement      176

Exception Specifications Theory and Practice      176

Summary      177

Online Resources      177

Exceptions During Construction and Destruction      178

Global Objects      178

Advanced Exception-Handling Techniques      178

Standard Exceptions      179

Exception Handlers Hierarchy      179

Exceptions and Performance      180

Misuses of Exception Handling      181

Summary      182

InformIT Articles and Sample Chapters      182

Online Resources      183

Chapter 12  Runtime Type Information (RTTI)      185

Getting Along Without RTTI      185

RTTI Constituents      187

dynamic_cast<>      190

Crosscasts      191

Downcasting from a Virtual Base      193

Summary      193

InformIT Articles and Sample Chapters      194

Online Resources      194

Chapter 13  The New Cast Operators      195

Presenting the New Cast Operators      195

static_cast      196

const_cast      197

reinterpret_cast      197

dynamic_cast      198

Summary      198

Online Resources      198

Chapter 14  Miscellaneous Techniques      201

Lock Files      201

Designing a Locking Policy      201

Implementation      202

Lock File Applications      203

Summary      203

Online Resources      204

Using the swap() Algorithm      204

Classic swap()      204

Swapping Without a Temporary Object      205

Another Temporary-Free Implementation      205

Summary      206

Using Class stopwatch for Performance Measurements      206

Design and Implementation      207

Analyzing Performance Using Class stopwatch      208

Summary      210

Signal Processing      210

Setting a Handler      210

Signaling a Process      211

ANSI <csignal> Limitations      211

Introducing POSIX Signals      212

Blocking Signals      213

Retrieving Pending Signals      213

Summary      213

Online Resources      213

Creating Persistent Objects      214

Serializing Built-In Datatypes      214

Serializing Class Objects      215

Performance Optimization      216

Summary      217

Online Resources      217

Bit Fields      218

Performance Analysis      218

Bit Field Usage      219

Space Optimization      219

Summary      220

Online Resources      221

Environment Variables      221

Defining Environment Variables from the Command Line      221

Reading an Environment Variable Programmatically      222

Setting an Environment Variable      223

Dealing with wchar_t Strings      224

Uses of Environment Variables      224

Summary      225

Online Resources      225

Variadic Functions      225

Uses of Variadic Functions      226

Implementation      226

Object-Oriented Alternatives to Variadic Functions      228

Summary      229

Online Resources      229

Chapter 15  Pointers to Functions, Pointers to Members, and Function
Objects      231

Pointers to Functions      231

Declaring a Function Pointer      231

Passing a Callback Function’s Address to Its Caller      233

Calling Conventions      233

Function Pointers and Ordinary Pointers      234

Summary      234

Pointers to Members      234

Declaring Pointers to Data Members      235

Manipulating a Data Member Through an Object      235

Manipulating a Data Member Through an Object’s Pointer      236

Declaring Pointers to Member Functions      236

The Underlying Representation of Pointers to Members      237

Summary      238

Online Resources      238

Function Object      238

Implementing a Function Object      239

Usage of Function Object      240

Template Function Objects      240

Function Objects in the Standard Library      241

Summary      242

Chapter 16  A Tour of C99      243

Borrowing from C++      243

inline Functions      243

Line Comments      244

Dispersed Statements and Declarations      244

Scope of for Loop Variables      244

Novel Core Features      245

Variable-Length Arrays      245

Designated Initializers      245

Variadic Macros      246

restrict-Qualified Pointers      247

long long Datatype      247

The __func__ Identifier      247

Obsolete Features      248

Obsolescing K&R Function Declaration Style      248

Implicit int      248

Summary      249

Chapter 17  Dynamic Linking      251

Static Linking Versus Dynamic Linking      251

Advantages of Dynamic Linking      251

Code Sharing      252

Automatic Updates      252

Security      252

Disadvantages of Dynamic Linking      252

The “DLL Hell” Problem      253

Aliasing      253

Code Cracking      253

Summary      254

Dynamic Linking by Example      254

Building a Shared Library      254

The <dlfcn.h> Interface      255

A <dlfcn.h> Example      256

Summary      257

Books      257

Chapter 18  Tips and Techniques      259

Using enums as Mnemonic Indexes      259

Properties of enum Types      259

Mnemonic Indexes Requirements      260

Mnemonic Indexes in Action      261

To enum But a Few      263

POD Initialization      264

Built-In Types      264

Arrays      265

Aggregates      266

Unions      267

Summary      268

Object Initialization      268

Assignment Versus Initialization      268

Member Initialization Lists      269

Obligatory Initialization      269

Class Constants      270

Summary      271

const Declarations      271

const Objects      271

const Pointers      272

const Member Functions      272

Complex Declarations      273

const Pointers of const Objects      273

operator const_cast<>      274

Summary      274

Sample Chapters      275

Books      275

Project Organization Guidelines      275

Units      275

Header Files Versus Source Files      276

The “One Entity” Rule      278

File Naming      278

Special Cases      279

Summary      280

inline Functions      280

inline Basics      280

Usage      281

inline Woes      282

Summary      283

Online Resources      283

Books      283

All About bool      283

The Pre-bool Era      284

Enter bool      285

bool Properties      286

Summary      287

Books      287

Bitwise Operators, Part I      287

Bitwise and Logical Operators      288

Bitwise Operators      288

Bitwise NOT      288

Bitwise AND      289

Bitwise OR      289

Bitwise XOR      290

Self-Assignment      290

Bit Shifting      290

Summary      292

Books and Online Books      292

Bitwise Operators, Part II      292

Resetting a Bit String      292

Setting a Bit String      293

Flipping a Bit String      294

Examining a Single Bit      294

Summary      295

Who’s this?      295

Analyze this      296

More About this      297

Reanalyze this      299

static Member Functions      299

Summary      300

Books      300

A Reference Guide      300

A Bit of History      300

Usage      303

Advantages of Pass by Reference      303

Summary      304

Books      304

The Virtues of Multiple Inheritance      304

Rationale      305

MI and the Deadly Diamond of Derivation      305

Tackling the Ambiguity Problem      306

Virtual Inheritance and Performance      307

Summary      308

Books      308

Interfaces      308

Interfaces Explained      308

Abstract Classes      310

Combining Multiple Interfaces      310

The DDD Strikes Again      311

Pure Virtual Functions–Final Refinements      312

Summary      312

Multiple Inheritance–Construction and Destruction Order      313

Construction and Destruction of Non-Virtual Bases      313

Construction and Destruction of Virtual Inheritance      316

Summary      318

typedef Declarations      318

typedef Basics      318

Curbing Convoluted Code      320

Storage Class Specifiers      320

Facilitating Code Portability      321

Summary      321

State of the union      322

What’s in a union?      322

union-Based Typecasting      323

Anonymous Unions      324

A union Facelift      325

Summary      326

dynamic_cast Uses      326

Limitations of Static Typecasting      326

Pointer Cast      328

Reference Cast      328

Crosscasts      329

Summary      330

Books      331

Integrating C and C++      331

Does C Still Matter?      331

Understanding ABI      331

Problems of Compiler-Specific ABIs      333

extern “C” Limitations      334

Summary      334

const Correctness      335

const Origins       335

The Meaning of const       335

const Crush Course       336

const Correctness in Practice      336

const Parameters      338

Summary      338

const Correctness–Advanced Issues      338

volatile Semantics      338

volatile Declarations      339

volatile Correctness in STL      340

mutable Data Members      340

Summary      341

Books      341

Sprucing Up Legacy Code      342

K&R Style Function Declarations      342

Using char* instead of void*      343

Compiled Binaries      343

Defaulting to int      343

Non-Tagged Data Structures      344

Summary      345

Books      345

Virtual Constructors      345

Rationale      345

Virtual Default Constructors      346

Virtual Copy Constructors      347

Memory Management Issues      348

Summary      348

Naming Names      348

The Case for Case-Sensitivity      349

What’s in an Identifier?      349

Reserved Identifiers      349

C Reserved Names      350

Keywords      350

Summary      351

Function Calls      352

What’s in a Function Call?      352

Function Overhead Scale      352

Thunks      352

Passing Arguments in Registers      353

Intrinsic Functions      353

Calling Conventions      354

Summary      354

Speaking Standardese      354

Side Effects      354

Sequence Points      355

The “Maximal Munch” Rule      356

Summary      357

Books      357

Declarations and Definitions      358

A Source of Confusion      358

Objects      358

Types      359

Functions      361

Summary      361

finally at Last?      362

 Exception Handling in C++ and Java      362

Destructors Versus finally()      362

Evaluation      364

Summary      365

Local Classes      365

A Local What?      365

Restrictions on Local Classes      366

Member Functions      367

Static Members      368

Summary      369

Complex Arithmetic      369

Complex Without Complications      369

Constructors and Initialization      371

Overloaded Operators      371

Additional Functions      371

Implicit Conversions      372

Summary      373

Floating-Point Woes      373

The Problem      373

Relative Operators      374

Remedies      375

Summary      375

The Object Model, Part I      376

Memory Layout of Data Members      376

Non-Virtual Member Functions      377

Static Member Functions      378

Virtual Member functions      378

Summary      380

The Object Model, Part II      380

Single Inheritance      380

Inheritance and Polymorphism      381

Multiple Inheritance      383

Virtual Inheritance      383

Summary      384

The Object Model, Part III      384

Embedded Objects      384

Advice      386

Empty Base Classes      387

Summary      388

Temporary Objects      388

Calling All Temps      388

Temporaries’ Anonymity      389

Temporaries’ Lifetime      390

Summary      391

Temporary Objects–Advanced Techniques      392

Explicit Instantiation of Temporaries      392

Syntax Musings      393

Summary      394

Over-Engineering      394

Exceptions      395

Over-Genericity      396

Excessive Operator Overloading      396

Summary      397

Online Resources      398

Migrating to 64-Bit Environments      399

Compatibility Issues      399

Built-in Types      399

Pointers      400

Member Alignment      400

ABI      400

Summary      401

Online Resources      401

Security Enhancements      402

C++ and Security      402

What About C?      402

memset() and Security      402

C-Style String Manipulation      404

Summary      405

Drop the (Automatic) Pilot      405

Embedded Literals      405

Avoid “Unnecessary Journeys”      406

Multithreading      406

Internationalization      407

Summary      407

Books      408

Arrays and Pointers      408

When Arrays Behave Like Pointers . . .       408

. . . and When They Don’t      409

sizeof Expressions      410

Array Wrapping      410

Summary      411

Low-Level File I/O, Part I      412

Back to the Source      412

open(), creat(), close(), and unlink()      412

read() and write()      414

Platform-Specific Issues      414

Low-Level File I/O, Part II      415

Buffered I/O and Non-buffered I/O      415

tell(), lseek() and eof()      415

Random Access: lseek()      416

eof() and Error Handling      417

Summary      418

static Declarations, Part I      418

Local statics      418

Initialization      419

Namespace Scope static Declarations      420

static Declarations, Part II      422

Initialization of Non-POD Objects      422

Static Data Members      423

Static Member Functions      423

Static Member Function Implementation      424

Deprecated–Alas, Unavoidable      425

Afterthoughts      426

Online Resources      426

Books      426

Static Initialization Order      427

Initialization Order Dependency      427

Working Around the Initialization Order Problem      428

Eliminating Initialization Order Dependency      429

Final Notes      430

Chapter 19  Design Patterns      431

Monostate Pattern      431

Problem Analysis      432

Enter Monostate      432

Putting It to Work      433

Summary      435

Books      435

Singleton Pattern      435

Rationale      436

Implementation      436

Design Considerations      437

Applications      438

Summary      439

Books      439

Anti-Patterns      439

What Is an Anti-Pattern?      440

The History Book on the Shelf . . .       440

. . . Is Almost Repeating Itself      440

Language-Specific Anti-Patterns      440

Analysis and Design Anti-Patterns      441

Organizational Anti-Patterns      441

Summary      442

Online Resources      442

Refactoring      442

What Is Refactoring?      442

Refactoring by Example      443

Refactoring Patterns      444

Summary      445

Chapter 20  C++0X: The New Face of Standard C++      447

Rationale      447

The <tuple> Library      448

Helper Functions      448

Applications      449

Summary      450

Reference Wrapper Class      450

Rationale      450

The reference_wrapper Class Template      451

Using reference_wrapper with Tuples      452

Summary      453

Chapter 21  The Reflecting Circle      455

The Future of Programming      455

Analysts’ Views–Early 1980s      455

Experts’ Views–2000—2001      456

Revolution? What Revolution?      457

The Conservative Party      457

Characters and Strings, Part I      458

What’s in a Character?      458

Double-Byte Coding      459

Unicode      459

String Representation      460

Recommended Books      460

Characters and Strings, Part II      461

Seven-Bit Strings      461

Length-Prefixing      461

Descriptors      463

Summary      463

Online Resources      464

Sound Bytes      464

Overture      464

Crescendo      465

Recitative      466

Diminuendo (Data Compression Versus Data Reduction)      466

Finale      467

Aspect-Oriented Programming      467

AOP and ISO C++      467

Another Silver Bullet?      468

Join-Points, Point-Cuts, and Advices      468

Around the Bend?      470

Epilogue      471

Index      473

Updates

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership