Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Allocator.h"
- class MyClassA {
- protected:
- int i = 0;
- MyAllocator& allocator;
- public:
- MyClassA(MyAllocator& allocator):
- allocator(allocator) {
- throw "Fail";
- }
- virtual ~MyClassA() {
- cout << "MyClassA::~MyClassA()" << endl;
- };
- void* operator new(size_t size, MyAllocator& allocator) {
- cout << "MyClassA::operator new(size_t size, MyAllocator& allocator)" << endl;
- cout << "size: " << size << " sizeof(MyClassA): " << sizeof(MyClassA) << endl;
- return allocator.allocate(size);
- }
- void operator delete(void *ptr, MyAllocator& allocator) {
- cout << "MyClassA::operator delete(void *ptr, MyAllocator& allocator)" << endl;
- cout << "sizeof(MyClassA): " << sizeof(MyClassA) << endl;
- allocator.deallocate(ptr, sizeof(MyClassA));
- }
- void operator delete(void *ptr, size_t size) {
- cout << "MyClassA::operator delete(void *ptr, size_t size)" << endl;
- cout << "size: " << size << " sizeof(MyClassA): " << sizeof(MyClassA) << endl;
- static_cast<MyClassA*>(ptr)->allocator.deallocate(ptr, size);
- }
- };
- int main() {
- MyAllocator* allocator = new MyAllocator();
- try {
- MyClassA* a = new(*allocator) MyClassA(*allocator); // C4291
- }
- catch (...) {
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment