Let's suppose we have a structure with a constant reference data member.
struct A {
A() : i{5} {}
const int& foo() const { return i; }
const int& i;
};
Do you have any idea why the output for an integer literal 5 is different?
A a{};
std::cout << a.i << std::endl;
std::cout << a.foo() << std::endl;
5
-858993460
Aucun commentaire:
Enregistrer un commentaire