0

How to access id using ptr?

class A
{
    int id;
public:
    int *ptr;
};


void main()
{
    int A::* ptr = &A :: id;
    getch();
}
Ziezi
  • 6,375
  • 3
  • 39
  • 49
Chaitanya Babar
  • 269
  • 3
  • 12
  • Possible duplicate of [How to access private data members outside the class?](http://stackoverflow.com/questions/6717163/how-to-access-private-data-members-outside-the-class) – Ziezi Jan 25 '16 at 23:05

1 Answers1

0

Try This

class A { 
    int id;
public:
    int *ptr= &id;
};

You can use the variable pointer to access id.

Ziezi
  • 6,375
  • 3
  • 39
  • 49
Rohit Vincent
  • 66
  • 1
  • 1
  • 6