DoehJohn
DoehJohn

Reputation: 233

Different ways of initializing an object with default constructor

class A {};

A a;// 1
A a{};// 2
A a = {};// 3
A a = A();// 4

There seems to be all options. Are 1, 2 and 3 are same and just the matter of style or there is some difference? 4 supposed to first create a temporary object and then assign it to an a, but it will happen only if I will turn off comliler's optimization completely, right?

Upvotes: 0

Views: 95

Answers (1)

eerorika
eerorika

Reputation: 238461

  1. Is different because it does default initialisation. This does not matter in case of A however, because there are no members to initialise.

Upvotes: 2

Related Questions