#include <iostream>
using namespace std;
class emp
{
private :
int i ;
int j;
public :
emp( )
{
i = 10 ;
j = 50 ;
}
void display()
{
cout<<endl<<i<<" "<<j<<endl;
}
} ;
int main( )
{
emp *p = new emp ;
p->display();
int *pi = (int*) p ;
cout << *pi ;
*pi = 20 ;
p->display();
delete p;
return 0;
}
I have two questions...
First: Isn't the above code shows flaw/hole in the language??I am able to access the private member of the class through typecasting
Second:If you see the output of this code...it comes out to be
10 50
10
20 50
How can i change the private data member j through the typecasted pointer