Abraxas/Meyers: Effective C++  Home  Table of Contents

Module - m17.html

ABRAXAS SOFTWARE - CodeCheck Meyers: Effective C++ Test-Suite

Meyers: Effective C++ Test Suite for Module - m17.cpp

// Item 17: Store newed objects in smart pointers in standalone statements. 75

// keep it simple, no headers, just a simple fwd decl for the shared_ptr ...

namespace std {
template  class shared_ptr {};
}
template  class foobar;
class Widget {
public:
	void pWidget( std::shared_ptr, int );
	void pWidget( Widget , int );
	int priority();
} ;
void Widget::pWidget( Widget w, int p )



Function Name: pWidget()

{
	{
		std::shared_ptr w( new Widget );	// good
		pWidget( w, p );
		foobar w( new Widget );				// bad
		pWidget( w, p );
	}
	{
		 pWidget( new Widget, p );	// bad
	}
}

Abraxas/Meyers: Effective C++  Home  Table of Contents

ABRAXAS SOFTWARE - CodeCheck Meyers: Effective C++ Test-Suite