#include<iostream>
using namespace std;
class A
{
    int value;
 public:
    A(){value = 1;}
    ~A(){}
    void print(){cout << value << endl;}
 };
int main()
{
    A a;
    int* p = (int*)(&a);
    *p = 20;
    a.print();//output is 20.
}
Does not this break a class's encapsulation? I'm a beginner of c++. I have never seen this method that can access to a class's private member in the book "c++ primer".
 
     
    