I know how to access std::string in class S, but how can i get int i in this class? What should i do? I understand i should shift the pointer, but in what way?
#include <iostream>
#include <string>
class S {
std::string s = "abcd";
int i = 9;
};
int main() {
S s;
auto* f = reinterpret_cast<std::string*>(&s);
std::cout << *f;
return 0;
}
i tried something like
auto* f = reinterpret_cast<char*>(&s); f += sizeof(std::string("abcd");
but it didn't work (i know it even looks silly but i tried >-< )