Can VB.NET be forced to initialize instance variables BEFORE invoking the base type constructor?

If you have virtual members that are going to be invoked during construction (against best advice, but we’ve already agreed on that), then you need to move your initialization into a separate method, that can protect itself against multiple calls (i.e. if init has already happened, return immediately). That method will then be invoked by … Read more

How to initialize a struct to 0 in C++

Before we start: Let me point out that a lot of the confusion around this syntax comes because in both C and C++ you can use the = {0} syntax to initialize all members of a C-style array to zero! See here: https://en.cppreference.com/w/c/language/array_initialization. So, this works: // z has type int[3] and holds all zeroes, … Read more

In what order are non-static data members initialized?

The order is the order they appear in the class definition – this is from section 12.6.2 of the C++ Standard: 5 Initialization shall proceed in the following order: — First, and only for the constructor of the most derived class as described below, virtual base classes shall be initialized in the order they appear … Read more

Why doesn’t Kotlin allow you to use lateinit with primitive types?

For (non-nullable) object types, Kotlin uses the null value to mark that a lateinit property has not been initialized and to throw the appropriate exception when the property is accessed. For primitive types, there is no such value, so there is no way to mark a property as non-initialized and to provide the diagnostics that … Read more

Is there a safe way to have a std::thread as a member of a class?

You can use a thread in combination with move semantics: class MyClass final { private: std::thread mythread; void _ThreadMain(); public: MyClass() : mythread{} // default constructor { // move assignment mythread = std::thread{&MyClass::_ThreadMain, this}; } }; The move assignment operator is documented on the following page. In particular, it is noexcept and no new thread … Read more

tech