You can dynamically create instances of a class using the new operator.
However, i guess you would also like to keep access to all the objects that you have created, which is not that simple unfortunately, but its not very hard either.
Since we need to keep reference to all the objects created, we will maintain them in a linked list. The nodes of the linked list will have the following members,
1. A pointer of type <class>
2. Next node pointer
Basic node step creation would be as follows,
1. Create an instance of linked list node
newnode = new LinkedListNode()
2. Connect the newly created node to previously maintained Linked List,
tail->nextnode = newnode
tail = newnode
**tail is a pointer which is maintained so as to always point at the tail of the linked list. Correspondingly, we need also to maintain a head pointer which points to start of the linked list.
3. Assign memory to the <class> pointer inside the new instance just created.
tail->classptr = new <class>()
Thus, you have dynamically created a new instance of class and at the same time you have maintained all the objects you have created so far. You can access each of these objects by traversing the list from head to tail.
-- AI
P.S -> Linked List is a form of data structure that helps you maintain "things" (in your case "things" were class objects) in the form of a list. This is not the only data structure that you can use. You can use anything from stack, queues, hashtables etc etc. to meet your needs and is most efficient as per your requirements.