+ 1
Whats the difference between private and public
c++
3 ответов
+ 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.
+ 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.
0
thanku for ur answer