This seems to compile and access the private data successfully. Is this well-defined behavior?
#include <iostream>
#include <string>
using std::string;
class foo {
string private_data = "Hello World";
};
int main()
{
foo f;
auto* pprivate_data = reinterpret_cast<string*>(&f);
std::cout << *pprivate_data << '\n';
}
This question is sort of similar, but I believe it doesn't address my question.