In C# I can write something like this:
class AnyThing
{
static public T Default = default(T);
}
static void Main ()
{
In C++ there is no something like default
keyword in C#. Since initialization by default constructor of value of class-type will be failed, if default constructor is private
. In C#, if default constructor is private, value of class-type will be initialized to null
, since class-type is reference-type
.
Initialition by {}
is defined by language specification. It's C++11. In C++03 you should use
T obj = T();
As pointed by bames53 in comment, when you want to initialize T*
you should use
before C++11.
T* obj = 0;
or
T* obj = NULL;
in C++11.
T* obj = {};
or
T* obj = nullptr;