mercredi 23 décembre 2015

Zero-reinitializing a struct in C++

A POD struct can be zero-initialized in C++11 as follows:

SomeStruct s{};

However, what do I do if I already have an instance of the struct and I want to re-initialize it to zeros? The following seems to work:

s = {};

Can someone point out the relevant standardese? I assume this is what is happening:

  1. A new zero-initialized instance gets created.
  2. The new instance is assigned to the existing instance, invoking the implicit assignment operator.

Aucun commentaire:

Enregistrer un commentaire