cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Classes C++
Classes C++
Feb 6, 2014 at 4:47am UTC
jshm415
(54)
Hi, I am studying classes and I came across this question. Is it possible that two objects from the same class assess each other's private variables?If so, how can this be done? I've always thought that private means private. Thank you
Feb 6, 2014 at 5:23am UTC
ak16
(119)
Hi jshm, See Assess of members is depend on where you are going to use them.
for private: its limited to own class.
for public: its not limited to class , you can access them out side the class.
So form above point you can not access private members of object out side the class whether they are from or from diff no matters.
I hope its clear now.
Feb 6, 2014 at 9:03am UTC
coder777
(8444)
Is it possible that two objects from the same class assess each other's private variables?
Yes. The access is limited to the class not the object
If so, how can this be done?
Like so:
1
2
3
4
5
6
7
8
9
10
11
class
a {
public
:
void
Set(
const
a &b) { x = b.x; }
private
:
int
x; };
Topic archived. No new replies allowed.