while reading the book < thinking in c++ 2>, I got the codes below:
#include <stdlib.h>
#include <iostream>
#pragma warning(disable : 4297)
using namespace std;
class buffer
{
public:
explicit buffer(size_t) throw();
~buffer() throw();
private:
char *const p;
};
buffer::buffer(size_t const count)
try
: p(new char[count])
{
cout << "constructor goes well......" << endl;
}
catch (...)
{
throw "hello";
abort();
}
buffer::~buffer()
{
delete[] p;
cout << "destructor also goes well......" << endl;
}
static void do_something_with(buffer &) throw()
{
cout << "something is done !" << endl;
}
int main()
{
buffer b(100);
do_something_with(b);
return 0;
}