Difference of keywords ‘typename’ and ‘class’ in templates?

typename and class are interchangeable in the basic case of specifying a template: and are equivalent. Having said that, there are specific cases where there is a difference between typename and class. The first one is in the case of dependent types. typename is used to declare when you are referencing a nested type that depends on another template parameter, such as the typedef in … Read more

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

Does the ‘mutable’ keyword have any purpose other than allowing the variable to be modified by a const function?

It allows the differentiation of bitwise const and logical const. Logical const is when an object doesn’t change in a way that is visible through the public interface, like your locking example. Another example would be a class that computes a value the first time it is requested, and caches the result. Since c++11 mutable can be … Read more

What is the “continue” keyword and how does it work in Java?

A continue statement without a label will re-execute from the condition the innermost while or do loop, and from the update expression of the innermost for loop. It is often used to early-terminate a loop’s processing and thereby avoid deeply-nested if statements. In the following example continue will get the next line, without processing the following statement in the loop. With a label, continue will re-execute from the loop … Read more