Ok, I'm trying to create an entity manager for my engine, and I'm encountering a problem that I can't seem to figure out. Here's my code for EntityManager.hpp:
#ifndef ENTITYMANAGER_H
#define ENTITYMANAGER_H
#include <memory>
#include <vector>
class Entity;
class EntityManager {
public:
void createEntity(std::unique_ptr<Entity>);
void destroyEntity(std::unique_ptr<Entity>);
void destroyAllEntities() { entities.clear(); }
private:
std::vector<std::unique_ptr<Entity> > entities;
};
#endif // ENTITYMANAGER_H
And it's corresponding cpp file:
#include <memory>
#include <vector>
#include <algorithm>
#include <iostream>
#include "EntityManager.hpp"
#include "Entity.hpp"
void EntityManager::createEntity(std::unique_ptr<Entity> entity) {
entities.push_back(entity);
}
void EntityManager::destroyEntity(std::unique_ptr<Entity> entity) {
bool entityFound = binary_search(entities.begin(), entities.end(), entity);
if (entityFound) {
auto iter = find(entities.begin(), entities.end(), entity);
entities.erase(iter, entities.end());
}
else
std::cout << "Could not find entity to destroy!" << std::endl;
}
When I try to compile this, it gives me an error in actual c++ files like unique_ptr.h, etc. I can't really post the errors because it's reaaaaally long but what I do know is that the problem is due to me trying to push a unique_ptr into my entities vector. I have also done the same thing with raw pointers to my Entity class (Entity*) and it worked fine, but I don't like dealing with raw pointers because they can get really annoying sometimes (destroying them correctly, etc) and it's just easier to use smart pointers. I hope you guys can help me and thank you for your time