-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrow.cpp
More file actions
57 lines (45 loc) · 1 KB
/
Copy patharrow.cpp
File metadata and controls
57 lines (45 loc) · 1 KB
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
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
class Entity {
public:
void Print() const {
std::cout<< "Hello" << std::endl;
}
~Entity() {
std::cout<< "Delete" << std::endl;
}
};
class ScopedPtr {
private:
Entity* m_Obj;
public:
ScopedPtr(Entity* entity)
:m_Obj(entity)
{
}
~ScopedPtr() {
std::cout<< "Delete from scoped" << std::endl;
delete m_Obj;
}
Entity* operator->(){
return m_Obj;
}
const Entity* operator->() const {
return m_Obj;
}
};
// code to Offset in the memory of a variable using arrow operator
struct Vector3 {
char x, y, z;
};
int main() {
/*
Entity e;
e.Print();
Entity* e_prt = new Entity();
e_prt->Print();
*/
const ScopedPtr scoped_e = new Entity();
scoped_e->Print();
int offset = (long int)&((Vector3*)nullptr)->z;
std::cout << offset << std::endl;
}