C++ default initialization and value initialization: which is which, which is called when and how to reliably initialize a template-type member

Not so hard: A x; A * p = new A; These two are default initialization. Since you don’t have a user-defined constructor, this just means that all members are default-initialized. Default-initializing a fundamental type like int means “no initialization”. Next: A * p = new A(); This is value initialization. (I don’t think there … Read more

Why can’t I refer to an instance method while explicitly invoking a constructor?

Non-static methods are instance methods. This are only accessible in existing instance, and instance does not exist yet when you are in constructor (it is still under construction). Why it is so? Because instance methods can access instance (non-static) fields, which can have different values in different instances, so it doesn’t make sense to call … Read more

iOS Designated Initializers : Using NS_DESIGNATED_INITIALIZER

The use of NS_DESIGNATED_INITIALIZER is nicely explained in http://useyourloaf.com/blog/2014/08/19/xcode-6-objective-c-modernization.html: The designated initializer guarantees the object is fully initialised by sending an initialization message to the superclass. The implementation detail becomes important to a user of the class when they subclass it. The rules for designated initializers in detail: A designated initializer must call (via super) … Read more

C++ – value of uninitialized vector

The zero initialization is specified in the standard as default zero initialization/value initialization for builtin types, primarily to support just this type of case in template use. Note that this behavior is different from a local variable such as int x; which leaves the value uninitialized (as in the C language that behavior is inherited … Read more