dimanche 28 mai 2023

why does default constructor being outside class or inside class make a difference in whether the class is POD?

In the following code, why is POD considered POD while notPOD considered not POD? The only difference between them is whether the definition for defaulted default constructor is placed inside or outside the class. I always thought that both do the same thing but it's apparently not the case.

#include <iostream>
struct POD {
    POD() = default;
};
struct notPOD {
    notPOD();
};
notPOD::notPOD() = default;
int main() {
    std::cout << std::boolalpha << std::is_pod<POD>() << ' ' << std::is_pod<notPOD>() << '\n';
}

Aucun commentaire:

Enregistrer un commentaire