[ create a new paste ] login | about

Link: http://codepad.org/lLJIyKwE    [ raw code | output | fork ]

C++, pasted on Nov 1:
#include <exception>
#include <iostream>


template <typename T>
class smart_ptr
{
public:
	smart_ptr(T* p) : m_p(p)
	{
		std::cout << "ctor smart_ptr" <<std::endl;
	}
	~smart_ptr()
	{
		std::cout <<"dtor smart_ptr" << std::endl;
		delete m_p;
	}
private:
	T* m_p;
};


class Widget
{
public:
	Widget()
	{
		//comment the following line out to see what happens
		//throw std::runtime_error("bad things happen");
	}
};

int main()
{
	
	try
	{
		smart_ptr<Widget> pWidget(new Widget());
	}
	catch( std::exception&)
	{
	}

	return 0;
}


Output:
1
2
ctor smart_ptr
dtor smart_ptr


Create a new paste based on this one


Comments: