0

what is the diffrance between structure and class?

3rd Oct 2017, 11:59 AM
Meow
2 odpowiedzi
+ 3
Just one: Structures have default access level as public. But classes have default access level as private. Thus, in the following struct: struct MyStruct { int code; char choice; }; The members code and choice are public, and are accessible in main, or any local function following this declaration. But in a class: class MyClass { int code; char choice; }; The members code and choice are private by default, and thus are inaccessible in main, or any local function following this declaration. Of course, you may change these rules by using the access modifiers, but this is the default (when you don't use any).
3rd Oct 2017, 12:38 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
@~swim~ Hmm. Never noticed that. But why is this so?
4th Oct 2017, 9:12 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar