On 29 April 2014 15:32, Jeff Hill wrote:
template <> shared_ptr < ChessPiece > NullObjectTypes < ChessPiece > :: factory () { static ChessPieceNull chessPieceNull; return shared_ptr < ChessPiece > ( &chessPieceNull, nullDeleter () ); }
N.B. This means every shared_ptr that owns the NullObject gets created with unique ownership, creating a new control block on the heap. Sometimes that might be what you want, but other times it would be better to copy an existing object so all null objects of a given type share ownership: template <> shared_ptr < ChessPiece > NullObjectTypes < ChessPiece > :: factory () { static ChessPieceNull chessPieceNull; static shared_ptr < ChessPiece > nullsp( &chessPieceNull, nullDeleter () ); return nullsp; } (This comment shouldn't be seen as endorsement of the proposal ;-)