+ 1

Whats the difference between private and public

c++

4th Dec 2016, 11:35 AM
Jonathan Daliwonga
Jonathan Daliwonga - avatar
3 Respuestas
+ 3
Let me show you an example: class SumStruct { public: int publicMember; private: int privateMember; }; The whole system knows that SumStruct contains publicMember, and hence can access/use it. Only SumStruct knows that privateMember exists. ONLY, which means that publicMember don't even know that privateMember exists. Which means that only SumStruct can use privateMember.
4th Dec 2016, 12:53 PM
Wen Qin
Wen Qin - avatar
+ 2
private and public are access modifiers. Private means you cannot access this function or variable outside of its object. (except you define some getter/setter). Public is the opposite and means you cann access public modifed functions and variables from any other class or object.
4th Dec 2016, 11:43 AM
Andreas K
Andreas K - avatar
0
thanku for ur answer
13th Apr 2021, 2:11 PM
Tejavath Priyanka
Tejavath Priyanka - avatar