C++ Object Instantiation vs Assignment

后端 未结 4 747
心在旅途
心在旅途 2020-12-05 08:47

What is the difference between this:

TestClass t;

And this:

TestClass t = TestClass();

I expected that th

4条回答
  •  情深已故
    2020-12-05 09:05

    The latter one could call copy constructor and thus requires one to be public.

    Edit: I certainly drew far too big conclusions from the type name you used. The sentence above only applies for class-types (i.e. not POD). For POD types, the former leaves the variable uninitialized, while the latter initializes it with so-called "default" value.

提交回复
热议问题