F
FBergemann
Hi,
i have a little question concerning Scott Meyer's Effective C++ (2nd
edition), Item 7 "Be prepared for out-of-memory conditions". It's
about his example for a class specific new_handler() management. Please
note that i don't want to start a discussion about the
purpose/usability of the approach. But i just want to understand some
technical issue of the example.
Here's the question:
Why does he define the member function
static void *operator new(size_t size);
as a *static* function for the class?
I can understand, that the
static new_handler set_new_handler(new_handler p);
Is defined as static. Because the user needs to invoke it for the class
itself , before creating an instance of the class (
X::set_new_handler(noMoreMemory) ).
But why using static for operator new()? It is not invoked on the user
level. Is it because the compiler needs to use it before there actually
is an instance of the object? (so the same reason, but this time the
compiler instead of the programmer?).
Can anyone confirm of tell me the right answer for this?
Thanks in advance!
Frank Bergemann
i have a little question concerning Scott Meyer's Effective C++ (2nd
edition), Item 7 "Be prepared for out-of-memory conditions". It's
about his example for a class specific new_handler() management. Please
note that i don't want to start a discussion about the
purpose/usability of the approach. But i just want to understand some
technical issue of the example.
Here's the question:
Why does he define the member function
static void *operator new(size_t size);
as a *static* function for the class?
I can understand, that the
static new_handler set_new_handler(new_handler p);
Is defined as static. Because the user needs to invoke it for the class
itself , before creating an instance of the class (
X::set_new_handler(noMoreMemory) ).
But why using static for operator new()? It is not invoked on the user
level. Is it because the compiler needs to use it before there actually
is an instance of the object? (so the same reason, but this time the
compiler instead of the programmer?).
Can anyone confirm of tell me the right answer for this?
Thanks in advance!
Frank Bergemann