, , , Node. , singleton, , , operator=() copy-constructor private. , , singleton (.. Accessor ).
class Node_S
{
private:
struct Node {
static const int INITIAL_SIZE = 100;
static Node* node_space;
static int OUT_OF_BOUNDS;
static Node BAD_NODE;
};
Node_S()
{
Node::OUT_OF_BOUNDS = 0;
Node::node_space = new Node[Node::INITIAL_SIZE];
Node::BAD_NODE = Node();
Node::node_space[Node::OUT_OF_BOUNDS] = Node::BAD_NODE;
}
Node_S(const Node_S&) {}
Node_S& operator=(const Node_S&) { return *this; }
public:
static Node_S& get_instance()
{
static Node_S singleton_instance = Node_S();
return singleton_instance;
}
};
Node_S::get_instance(). private, ... . , . , , Node get_instance(). singleton_instance - , , Node_S() , Node . , Node Node_S. , :
Node_S::Node a_node_copy = Node_S::get_instance().get_node(10);