Throw an Exception While Construction An Object

xiaoxiao2021-03-06  42

While Reading The Book , I Got The Codes Below: #include #include

#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;}

转载请注明原文地址:https://www.9cbs.com/read-57306.html

New Post(0)