- Specify which members of structures and classes are accessible to clients and which are not
- Members that are declared public are accessible; members declared private are not
- By default, members of a struct are public and members of a class are private
The previous example is equivalent to this:
struct EmployeeA // EmployeeA is a new type
{
public: // members are visible
char firstName[10]; // first name is a char array
char lastName[12]; // last name is char array
float salary; // yearly pay is float
int years; // years of service
};
class EmployeeB // EmployeeB is a new type
{
private: // members are not visible
char firstName[10]; // first name is a char array
char lastName[12]; // last name is char array
float salary; // yearly pay is float
int years; // years of service
};
The access specifiers are redundant. However, you should always provide an access specifier for classes. You will typically not provide any for structures. This means that structure members will always be accessible.