+ 1
Can we access a private variable using pointer in C++
Suppose there is a code snippet class test { int a; }; int main() { test obj; int* ptr; } how can I store the address of obj .a in ptr. ?
3 Answers
+ 1
You can use a function in test to point ptr at a, but if you do that you could also just make a public in the first place...
+ 1
just using the pointer and c++ statements only.... no functions
0
Well, you need to find the variable somehow, if you don't want functions you'll need a public pointer to a in test.