This may not be the biggest question, but since classes in C ++ have all their attributes and methods private by default, does it make sense to specify it?
Is this just a matter of preference? Does the private part determine code that looks more or less experienced?
class User { string name; string surname; int miles; double balance; public: User(string,string,int,double); };
against
class User { private: string name; string surname; int miles; double balance; public: User(string,string,int,double); };
All style and matter of preference.
, , , , , , ( ) , ). private , , , , struct, ( public, 't structs, , ).
private
struct
public
structs
, . . , private , class, . , , , ..
class
, , , , , . - , : . , (: ). , , , . "" , , , , , . . .
. - , java, , private. default - . , , , - private. , , C++.
default
C++
This is just a matter of preference.
struct Foo { public: // These are already public; no need to write it void a(); int b; private: // You need this one though char c; };
Similarly:
class Bar { private: // These are already private; no need to write it void a(); int b; public: // You need this one though char c; };