add smart pointers

add polymorphism
add destructor & copy constructor
add pointer-pointer
This commit is contained in:
2025-09-22 18:22:03 +02:00
parent d8f6014fab
commit 3b35b973c9
13 changed files with 208 additions and 7 deletions
+27 -2
View File
@@ -3,6 +3,8 @@
#include "Entity.h"
#include "Monster.h"
#include "Vector3.h"
#include "ICompareable.h"
#include "Ork.h"
using namespace std;
@@ -11,8 +13,9 @@ int main()
Entity entity; // this is an entity instance
cout << entity.toString() << endl;
Monster monster;
cout << monster.toString() << endl;
// can't be instantiated because of abstract method
//Monster monster;
//cout << monster.toString() << endl;
Vector3 position;
Vector3 position2(1.0f, 0.0f, -10.0f);
@@ -20,5 +23,27 @@ int main()
Vector3 position4{}; // list-initializer
Vector3 position5 = {}; // list-initializer assigned
Ork ork;
ICompareable* pComparable = nullptr;
pComparable = &ork;
pComparable->Compare(&ork);
(*pComparable).Compare(&ork); // same as line above, but more complicated to write
ICompareable* pComparables[] = { new Ork, new Ork, new Ork };
for (size_t i = 0; i < size(pComparables); i++)
{
pComparables[i]->Compare(&ork);
delete pComparables[i];
pComparables[i] = nullptr;
}
// creates an "dynamic" heap pointer array
ICompareable** pHeapComparables = new ICompareable*[10];
delete[] pHeapComparables;
pHeapComparables = nullptr;
Ork ork2 = ork; // should be a individual instances with their own values and weapons
return 0;
}