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 is using [DataMember(EmitDefaultValue = false)] not recommended?

The reason is at the bottom of the article that you link to. The short version is: When the EmitDefaultValue is set to false, it is represented in the schema as an annotation specific to Windows Communication Foundation (WCF). There is no interoperable way to represent this information. In particular, the “default” attribute in the … Read more

What can a const member function change? [duplicate]

What can a ‘const’ method change? Without explicitly casting away constness, a const member function can change: mutable data members, and any data the class has non-const access to, irrespective of whether that data’s accessible: via member variables that are pointers or references, via pointers or references passed as function arguments, via pointers or references … Read more

How do class members get initialized if I don’t do it explicitly?

In lieu of explicit initialization, initialization of members in classes works identically to initialization of local variables in functions. For objects, their default constructor is called. For example, for std::string, the default constructor sets it to an empty string. If the object’s class does not have a default constructor, it will be a compile error … Read more

What can a ‘const’ method change?

What can a ‘const’ method change? Without explicitly casting away constness, a const member function can change: mutable data members, and any data the class has non-const access to, irrespective of whether that data’s accessible: via member variables that are pointers or references, via pointers or references passed as function arguments, via pointers or references … Read more

Does the ‘mutable’ keyword have any purpose other than allowing a data member to be modified by a const member 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 … Read more

WCF: Exposing readonly DataMember properties without set?

Your “server-side” class won’t be “made available” to the client, really. What happens is this: based on the data contract, the client will create a new separate class from the XML schema of the service. It cannot use the server-side class per se! It will re-create a new class from the XML schema definition, but … Read more

When to use DataContract and DataMember attributes?

Since a lot of programmers were overwhelmed with the [DataContract] and [DataMember] attributes, with .NET 3.5 SP1, Microsoft made the data contract serializer handle all classes – even without any of those attributes – much like the old XML serializer. So as of .NET 3.5 SP1, you don’t have to add data contract or data … Read more