Embed
Email

Effective-C++-Cheat-Sheet

Document Sample

Shared by: gegeshandong
Categories
Tags
Stats
views:
0
posted:
10/27/2011
language:
English
pages:
1
Effective C++ Cheat Sheet

Book by Scott Meyers – Cheat Sheet by Christopher Gilbert



Accustoming Yourself to C++ Strive for exception-safe code

View C++ as a federation of languages Understand the ins and outs of inlining

Prefer consts, enums and inlines to #defines Minimize compilation dependencies between files

Use const whenever possible Inheritance and Object-Oriented Design

Make sure that objects are initialized before they’re used Make sure public inheritance models “is-a”

Constructors, Destructors, and Assignment Operators Avoid hiding inherited names

Differentiate between inheritance of interface and

Know what functions C++ silently writes and calls

inheritance of implementation

Explicitly disallow the use of compiler-generated functions

Consider alternatives to virtual functions

you do not want

Declare destructors virtual in polymorphic base classes Never redefine an inherited non-virtual function

Never redefine a function’s inherited default parameter

Prevent exceptions from leaving destructors

value

Never call virtual functions during construction or Model “has-a” or “is-implemented-in-terms-of” through

destruction composition

Have assignment operators return a reference to *this Use private inheritance judiciously

Handle assignment to self in operator= Use multiple inheritance judiciously

Copy all parts of an object Templates and Generic Programming

Understand implicit interfaces and compile-time

Resource Management

polymorphism

Use objects to manage resources Understand the two meanings of typename

Think carefully about copying behaviour in resource-

Know how to access names in templatized base classes

managing classes

Provide access to raw resources in resource-managing

Factor parameter-independent code out of templates

classes

Use the same form in corresponding uses of new and Use member function templates to accept “all compatible

delete types”

Store newed objects in smart pointers in standalone Define non-member functions inside templates when type

statements conversions are desired

Designs and Declarations Use traits classes for information about types

Make interfaces easy to use correctly and hard to use

Be aware of template metaprogramming

incorrectly

Treat class design as type design Customising new and delete

Prefer pass-by-reference-to-const to pass-by-value Understand the behaviour of the new-handler

Don’t try to return a reference when you must return an Understand when it makes sense to replace new and

object delete

Declare data members private Adhere to convention when writing new and delete

Prefer non-member non-friend functions to member

Write placement delete if you write placement new

functions

Declare non-member functions when type conversions

Miscellany

should apply to all parameters

Consider support for a non-throwing swap Pay attention to compiler warnings

Implementations Familiarise yourself with the standard library, including TR1

Postpone variable definitions as long as possible Familiarise yourself with Boost

Minimise casting

Avoid returning “handles” to object internals



Related docs
Other docs by gegeshandong
Mar - Mr Hanson
Views: 0  |  Downloads: 0
WhatDoYouMeanHighest.Price
Views: 0  |  Downloads: 0
core data
Views: 0  |  Downloads: 0
jan-18-2009b
Views: 0  |  Downloads: 0
Status - California State University
Views: 0  |  Downloads: 0
PHASE ONE
Views: 0  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!