Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


Component.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef COMPONENT_H_
#define COMPONENT_H_

class Entity;

class Component {
private:
	Entity* parentPtr;

public:
	virtual void init();
	virtual void update();
	virtual ~Component();
	void setParent(Entity* mParentPtr);
};

#endif /* COMPONENT_H_ */

Entity.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef ENTITY_H_
#define ENTITY_H_

#include "Component.h"

class Entity {
private:
	std::vector<Component*> componentPtrs;

public:
	~Entity();
	void addComponent(Component* mComponentPtr);
	void delComponent(Component* mComponentPtr);
	void update();
};

#endif /* ENTITY_H_ */

Component.cpp

1
2
3
#include "Component.h"

void Component::setParent(Entity* mParentPtr) { parentPtr = mParentPtr; }

Entity.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <sstream>
#include <algorithm>

#include "Entity.h"
#include "Component.h"

Entity::~Entity() {
	for (auto &componentPtr : componentPtrs) delete componentPtr;
}
void Entity::addComponent(Component* mComponentPtr) {
	componentPtrs.push_back(mComponentPtr);
	mComponentPtr->setParent(this);
}
void Entity::delComponent(Component* mComponentPtr) {
	componentPtrs.erase(remove(componentPtrs.begin(), componentPtrs.end(), mComponentPtr), componentPtrs.end());
	delete mComponentPtr;
}
void Entity::update() { for (auto &componentPtr : componentPtrs) componentPtr->update(); }

Eclipse error log (plain_text)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Description	Resource	Path	Location	Type
Invalid arguments '
Candidates are:
void push_back(Component * const &)
'	Entity.cpp	/TestEntity	line 15	Semantic Error
Invalid arguments '
Candidates are:
__gnu_cxx::__normal_iterator<Component * *,std::vector<Component *,std::allocator<Component *>>> erase(__gnu_cxx::__normal_iterator<Component * *,std::vector<Component *,std::allocator<Component *>>>)
__gnu_cxx::__normal_iterator<Component * *,std::vector<Component *,std::allocator<Component *>>> erase(__gnu_cxx::__normal_iterator<Component * *,std::vector<Component *,std::allocator<Component *>>>, __gnu_cxx::__normal_iterator<Component * *,std::vector<Component *,std::allocator<Component *>>>)
'	Entity.cpp	/TestEntity	line 19	Semantic Error
Method 'update' could not be resolved	Entity.cpp	/TestEntity	line 22	Semantic Error
Invalid arguments '
Candidates are:
#0 remove(#0, #0, const #1 &)
'	Entity.cpp	/TestEntity	line 19	Semantic Error