What is the meaning of ‘const’ at the end of a member function declaration?

When you add the const keyword to a method the this pointer will essentially become a pointer to const object, and you cannot therefore change any member data. (Unless you use mutable, more on that later). The const keyword is part of the functions signature which means that you can implement two similar methods, one … Read more

Difference between local allocatable and automatic arrays

For the sake of clarity, I’ll briefly mention terminology. The two arrays are both local variables and arrays of rank 1. alloc_array is an allocatable array; automatic_array is an explicit-shape automatic object. Being local variables their scope is that of the procedure. Automatic arrays and unsaved allocatable arrays come to an end when execution of … Read more

Java, What is the difference between assigning null to object and just declaration

It depends on the scope where you declare the variable. For instance, local variables don’t have default values in which case you will have to assign null manually, where as in case of instance variables assigning null is redundant since instance variables get default values. public class Test { Object propertyObj1; Object propertyObj2 = null; … Read more

Is is a good practice to put the definition of C++ classes into the header file?

The answer depends on what kind of class you’re creating. C++’s compilation model dates back to the days of C, and so its method of importing data from one source file into another is comparatively primitive. The #include directive literally copies the contents of the file you’re including into the source file, then treats the … Read more