Assume an object can be cited (or referenced) by other objects. Currently I use a member variable to record its citation count. The citation count is used to determine if the object can be deleted or not.
class Cited
{
public:
int m_citationCount;
};
I make the variable public. When the object is cited, it is increased by 1. If it is uncited, it is decreased by 1. Making the variable public doesn't seem proper. If it has only one type of citer, I can make the citer type a friend. However, there may be all kinds of citers. Any better idea to do it?
More information: These objects are items or nodes in a tree structure. Some nodes may reference other nodes. For example, a node is called air which represents material air with its properties like density. A node called background may reference the air node to show the background is air. Operations on the tree are undoable. If a user deletes the background node, it is just pushed in an undo stack. It is not really deleted.