+ 3

Can the private members of a class be accessed without using any public function??

27th Dec 2017, 6:12 AM
Ankit Pal
Ankit Pal - avatar
3 ответов
+ 4
No you cannot. Thats the whole point of the permission levels. Even friend functions that are allowed to access/manipulate private class variables [publicly] are technically 'public' functions you're creating to do so. I do imagine though, with some 'trickery' you could use some virtual functions & templates, mess around with some pointers & structs to hack into the private scope somehow. Maybe even try to use pointer manipulation of an object's memory allocation that you know are certain sizes. Basically I think it's possible but not with any conventional use.
28th Dec 2017, 5:55 AM
Ammon Miranda
+ 3
no, to use private it must be accessed into public
27th Dec 2017, 6:25 AM
🦋FEATHER🦋
🦋FEATHER🦋 - avatar
+ 1
Yes, if you use the "friend" keyword you can access private members outside of the class. More details and examples: http://en.cppreference.com/w/cpp/language/friend
27th Dec 2017, 6:49 AM
aklex
aklex - avatar