原创 codecomplexity

// 1.invokes the Employee copy constructor. This copy operation might throw an exception String EvaluateSalaryAndRetur

原创 writing exception cod2

template<class T> class Stack { public: Stack(); ~Stack(); Stack(const Stack& other); Stack& operator=(const Stack

原创 Writing Exception Code

template<class T> class Stack { public: Stack(); ~Stack(); Stack(const Stack& other); Stack& operator=(const Stack

原创 NameLookupAndInterfacePrinciple1

namespace A { struct X; struct Y; void f( int ); void g( X ); } namespace B { void f( int i ) { f( i

原创 Maximally Reusable Generic Containers

template<typename T, size_t size> class fixed_vector { public: typedef T* iterator; typedef const T* const_iterato

原创 static 的作用

對於一個完整的程序,在內存中的分佈情況如下圖:   代碼區 //low address  全局數據區   堆區   棧區 //high address 1、全局變量和全局靜態變量的區別, example: #include <iost

原创 The "Fast Pimpl" Idiom

// file y.h class X; class Y { /*...*/ X* px_; }; // file y.cpp #include "x.h" Y::Y() : px_( new X ) {} Y::~Y(

原创 Temporary Objects

string FindAddr(list<Employee> emps, string name) // const &, string& dangerous. { // for most containers, calling end

原创 Minimizing Compile-time Dependencies 1

// x.h: original header // #include <iostream> // remove, unnecessary #include <ostream> // std, typedef. it can

原创 Uses And Abuses of Inheritance

Use inheritance wisely. If you can express a class relationship using containment/delegation alone, you should always p

原创 classrelationships1

class BasicProtocol /* : possible base classes */ // MessageCreator or MessageHelper. { public: BasicProtocol();

原创 NameLookupAndInterfacePrinciple2

//*** Example 5 (a) -- nonvirtual streaming class X { /*...ostream is never mentioned here...*/ }; ostream& operato

原创 Case-Insensitive

/* ci_string s( "AbCdE" ); // case insensitive // assert( s == "abcde" ); assert( s == "ABCDE" ); // still case-pr

原创 NameLookup4

// Example 2: Will this compile? // // In some library header: namespace N { class C {}; } int operator+(int i, N::C)

原创 overring virtual functions

#include <iostream> #include <complex> using namespace std; class Base { public: virtual void f( int ); virtual