
Untitled
By: a guest on
Aug 11th, 2012 | syntax:
None | size: 0.80 KB | hits: 6 | expires: Never
operator new with empty exception-specification calling constructor when allocation returns 0
void * operator new (size_t s, PersistentMemory * m) throw()
{return m->allocatePersistentMemory(s);}
void *myalloc (size_t) { return 0; }
void * operator new (size_t s) throw() { return myalloc(s); }
struct Foo {
std::string s;
Foo () { std::cout << this << std::endl; }
};
int main () {
Foo *f = new Foo;
if (f == 0) std::cout << "f is NULL" << std::endl;
}
void *myalloc (size_t) { return 0; }
void * operator new (size_t s) throw() { return myalloc(s); }
struct Foo {
std::string s;
Foo () { std::cout << this << std::endl; }
void * operator new (size_t s) { return myalloc(s); }
};
int main () {
Foo *f = new Foo;
if (f == 0) std::cout << "f is NULL" << std::endl;
}