+ 2

If there is a class and it has only one int type data member in it and that is also private. Can we use it outside the class?

Outside the class here doesn't symbolises to a friend function, it represents main(). And if we can access it outside the class then what does data abstraction mean then???

10th Mar 2018, 5:57 AM
Nikhil Punwani
7 Respostas
+ 2
just make a class type object "A" and a class type pointer that is refering to that object "A"... Now dereference it wherever you want. you will get the value of that data member.
10th Mar 2018, 6:45 AM
Nikhil Punwani
+ 4
recently i learning c++.. and i think u cannot access a private data member outside the class.. If its public, then the data member can be easily accessed using the direct member access (.) operator with the object of that class. If, the data member is defined as private or protected, then we cannot access the data variables directly. https://www.studytonight.com/cpp/accessing-data-members.php
10th Mar 2018, 6:01 AM
Scooby
Scooby - avatar
+ 4
sure.. tell me
10th Mar 2018, 6:39 AM
Scooby
Scooby - avatar
+ 3
sounds good...ok..i'll check later..
10th Mar 2018, 6:49 AM
Scooby
Scooby - avatar
+ 1
bro actually there is one way. I may give you a hint if you want. It can be done using pointers...
10th Mar 2018, 6:35 AM
Nikhil Punwani
0
actually I have got one way but don't know whether it is right or not???
10th Mar 2018, 6:00 AM
Nikhil Punwani
0
ya sure please check it and tell me if it works bcz it's from my mind.. I too need to know whether it's right or not
10th Mar 2018, 6:50 AM
Nikhil Punwani