So one thing that kills me a lot in c++ is the switch statement. As you all know switch statements look like the following.

1
2
3
4
5
6
7
8
9
10
11
12
auto s = 0;

switch(s)
{
case 0:
doSomething();
break;
case 1:
doSomething1();
break;

}
Continue reading

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 stack.

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.
Continue reading

  • page 1 of 1

Tommy "TerribleDev" Parnell

Hi, my name is Tommy. I work very hard to deliver quality content, free. If I helped you please consider donating.


Software Engineer II


Boston Area