Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <memory>
- struct Toto {
- int a;
- static void* operator new(size_t n)
- {
- return malloc(n);
- }
- static void operator delete(void* ptr, size_t)
- {
- return free(ptr);
- }
- };
- int main(int argc, char** argv) {
- std::unique_ptr<Toto> buf(new Toto{argc});
- if (!buf) {
- return 1;
- }
- printf("%d\n", buf->a);
- std::unique_ptr<int, decltype(free)*> MyInt((int*)malloc(sizeof(int)), free);
- if (!MyInt) {
- return 1;
- }
- *MyInt = argc+10;
- printf("%d\n", *MyInt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement