-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayofobj.cpp
More file actions
46 lines (39 loc) · 825 Bytes
/
Copy patharrayofobj.cpp
File metadata and controls
46 lines (39 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <stdlib.h>
class MyClass
{
int _mymember;
public:
MyClass()
{
std::cout << "Constructor is called\n";
}
~MyClass()
{
std::cout << "Destructor is called\n";
}
void *operator new[](size_t size) //Aleays total size+ 8 bytes is used for allocation overhead
{
std::cout << "new: Allocating " << size << " bytes of memory" << n << std::endl;
void *p = malloc(size);
return p;
}
/*
void *operator new[](size_t size, int t)
{
std::cout << "newer";
void *n;
return n;
}
*/
void operator delete[](void *p)
{
std::cout << "delete: Memory is freed again " << std::endl;
free(p);
}
};
int main()
{
MyClass *p = new MyClass[3]();
delete[] p;
}