Files
gpd-924-en/CPlusPlus/Classes/main.cpp
T
david 3b35b973c9 add smart pointers
add polymorphism
add destructor & copy constructor
add pointer-pointer
2025-09-22 18:22:03 +02:00

49 lines
1.2 KiB
C++

#include <iostream>
#include "Entity.h"
#include "Monster.h"
#include "Vector3.h"
#include "ICompareable.h"
#include "Ork.h"
using namespace std;
int main()
{
Entity entity; // this is an entity instance
cout << entity.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);
Vector3 position3 = Vector3();
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;
}