28static int g_alloc_counter = 0;
29static int g_fail_at_alloc_count = -1;
34 if (g_fail_at_alloc_count != -1) {
36 std::cerr <<
">>> Debug: operator new called. Count: " << g_alloc_counter <<
", Size: " << size <<
" bytes."
38 if (g_alloc_counter >= g_fail_at_alloc_count) {
39 std::cerr <<
"--- Forcing std::bad_alloc at allocation #" << g_alloc_counter <<
" ---" <<
std::endl;
54void operator delete(
void *ptr)
throw() {
std::free(ptr); }
57 std::cout <<
"--- Test RAII( Resource Acquisition Is Initialization ) ---" <<
std::endl;
70 g_fail_at_alloc_count = 3;
The Animal class represents a generic animal.
The Cat class represents a feline animal.
The Dog class represents a canine animal.
Declares the abstract Animal base class.
ScopedPointer Class is Custom smart pointer with RAII pattern applied.