Issue
I have a class A
as mentioned below:-
class A{
int iData;
};
I neither want to create member function nor inherit the above class A
nor change the specifier of iData
.
My doubts:-
- How to access
iData
of an object sayobj1
which is an instance ofclass A
? - How to change or manipulate the
iData
of an objectobj1
?
Note: Don't use friend
.
Solution
You can't. That member is private, it's not visible outside the class. That's the whole point of the public/protected/private modifiers.
(You could probably use dirty pointer tricks though, but my guess is that you'd enter undefined behavior territory pretty fast.)
Answered By - Mat Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.