Should the label be "private" in C ++ classes? Does it really matter?

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);

};
+4
source share
3 answers

All style and matter of preference.

, , , , , , ( ) , ). private , , , , struct, ( public, 't structs, , ).

, . . , private , class, . , , , ..

, , , , , . - , : . , (: ). , , , . "" , , , , , . . .

+4

. - , java, , private. default - . , , , - private. , , C++.

+3

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;
};
+1
source

All Articles