[Solved] How to create objects dynamically? [closed]


The keyword new lets you create a new object. C++ is a little different than a language like .Net or Java, if you are familiar with those languages. The C++ languages uses the keyword new, but new return a “pointer” to the new object. If your class is named “Bet”, then the statement:

Bet *betPointer = new Bet();

Will create a new “Bet” object and assign its pointer to the variable “betPointer”.

If bet has a property names “color” that return a string, then instead of writing:

betPointer.color //this is wrong

betPointer->color //this is correct.

My favorite site to research these kinds of questions is http://www.cplusplus.com. Follow this link for a more information and examples using the keyword new:
http://www.cplusplus.com/reference/new/operator%2k0new/

solved How to create objects dynamically? [closed]