Using pointer, I am able to modify the private value of the class in the code below.
Does it violate the C++ concept that private member can only be modified by member or friend functions?
#include<iostream>
using namespace std;
class demo
{
private: int info;
public:
demo()
{
info=10;
}
void print_info()
{
cout<<info;
}
};
int main()
{
demo ob;
int* ptr=(int*)&ob;
*ptr=20;
ob.print_info();
return 0;
}