I was reading about structs and struct padding and I wrote this code. It edits a private member of a struct using its address offset from a. Does this mean you can take a class someone made and extract/change private varriables and functions?
#include <iostream>
typedef struct x {
int a;
private:
int b;
public:
//Init
x(int a, int b) : a(a) , b(b){}
void print(){
//Print values
std::cout << a << " " << b << std::endl;
}
} x;
int main()
{
struct x s(10,20) ;
int *p = (int *)(((char*)&s)+4); //4 Byte offset from a (a is at base)
s.print();
(*p) +=1;
s.print();
//Stops terminal closing
int junk;
std::cin >> junk;
return 1;
}