I have a program that creates a random amount of points interspersed throughout the program. While it runs, I would also like to create an object for each point and store it in a vector. I have created a Point class with various attributes but I have no idea on how to implement the above. When looking at other questions that deal with similar, yet nonidentical problems, pointers are used, but again, I have no idea on how to implement them.
I have a program that creates a random amount of points interspersed throughout the
Share
Im not quite sure what you really want to achieve, but i hope this will help you though.
To create an object dynmically use the
newoperator. Thenewoperator always returns a pointer:If you have specified a constructor the call is very similar to normal construction on stack:
A std::vector stores objects at runtime (dynamically in the heap), but instead of creating them by it own it simply copies them: