I was going through one of the examples of C++, for cloning of an object.
#ifndef CLIPBOARDSTACK_H
#define CLIPBOARDSTACK_H
#include <QStack>
#include "getEntity.h"
class clipboardStack
{
public:
static clipboardStack *instance()
{
if (!inst)
inst = new clipboardStack;
return inst;
}
void push(getEntity *entity)
{
clips.push(entity);
}
getEntity *pasteEntity()
{
if (clips.count() == 0)
return 0;
return clips.last();
}
getEntity *pop()
{
if (clips.count() == 0)
return 0;
return clips.pop();
}
bool isEmpty() const
{
return clips.empty();
}
private:
QStack<getEntity *> clips;
static clipboardStack *inst;
};
#endif // CLIPBOARDSTACK_H
where getEntity is:
#ifndef GETENTITY_H
#define GETENTITY_H
#include <QGraphicsItem>
class getEntity : public QObject, public QGraphicsItem
{
public:
getEntity(QObject *parent = 0) : QObject(parent) {}
virtual ~getEntity() {}
virtual getEntity *clone()
{
return 0;
}
};
#endif // GENTITY_H
But I couldn't get what exactly the line means.
What is the meaning of the line:
static clipboardStack *instance()
{
if (!inst)
inst = new clipboardStack;
return inst;
}
Can someone explain me what does above line exactly do, and the two classes in brief?