Reputation: 11733
this is my class:
#ifndef POINTPOOL_H_
#define POINTPOOL_H_
#include <list>
#include <iostream>
#include "ofPoint.h"
// adapted from https://gist.github.com/1124832
class PointPool
{
private:
std::list<ofPoint*> resources;
static PointPool* instance;
PointPool() {};
public:
~PointPool() {}; // 1
static pointPool* getInstance() // 2
{
if (instance == 0)
{
instance = new PointPool();
}
return instance;
}
Resource* getPoint()
{
if (resources.empty())
{
std::cout << "Creating new." << std::endl;
return new ofPoint();
}
else
{
std::cout << "Reusing existing." << std::endl;
ofPoint* resource = resources.front();
resources.pop_front();
return resource;
}
}
void disposePoint(ofPoint* object)
{
object->x = 0;
object->y = 0;
object->z = 0;
resources.push_back(object);
}
};
PointPool* PointPool::instance = 0;
#endif /* POINTPOOL_H_ */
i get
expected unqualified-id at end of input
at comment 1 and
expected ‘;’ before ‘*’ token
at comment 2 i tried to google but i don't fine a link between this compiler message error and my code..
Upvotes: 1
Views: 75
Reputation: 30042
You also have a typo in pointPool*
, which should be PointPool*
. Fixing it should clear both errors.
Upvotes: 1
Reputation: 3358
You need to change this:
static pointPool* getInstance()
To this:
static PointPool* getInstance()
The semicolons after your constructor and destructor are also unnecessary. And, as Ed mentioned, the definition of PointPool::instance must not be in the header.
Upvotes: 2
Reputation: 60017
This line PointPool* PointPool::instance = 0;
should be in the .cpp file - otherwise you are going to have multiple copies.
Upvotes: 1