When should I use the new keyword in C++?

Method 1 (using new) Allocates memory for the object on the free store (This is frequently the same thing as the heap) Requires you to explicitly delete your object later. (If you don’t delete it, you could create a memory leak) Memory stays allocated until you delete it. (i.e. you could return an object that you created using new) The example in the question will leak memory unless … Read more

how does the ampersand(&) sign work in c++?

To start, note that is a special pointer ( == memory address) to the class its in. First, an object is instantiated: Next, a pointer is instantiated: Next, the memory address of a is assigned to the pointer b: Next, the method CDummy::isitme(CDummy &param) is called: A test is evaluated inside this method: Here’s the tricky part. param is an … Read more