I was under the impression that all const members had to be explicitly initialized by the constructor once, but after testing it seems as if only POD types have to be initialized. The following compiles regardless of whether b is mentioned in the constructor or not:
#include <string>
struct A {
const int a;
const std::string b;
A() : a{} {}
};
Example: http://cpp.sh/36my2
Aucun commentaire:
Enregistrer un commentaire