So I have started learning c++ recently, and as a .NET/Java developer I always want to write the following code.
var s = new myClass().
In c++ you have to manage memory yourself, there is no garbage collector.
If you do not use the new keyword
var s = myClass() you will create that class and assign it to on the
Any stack variables will be cleaned at the end of the block, so in this case s will be cleaned. However if you use
var s = new myClass() s will be allocated onto the heap and must be deleted, otherwise memory leaks will occur.
To clean the variable you must call
delete when you are done with the variable, this will cause the memory in the heap to be cleaned.