Making class members private instead of public is one of the fundamental parts of Object-Oriented Programming:
Encapsulation.
https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)
Yes, making something public instead of private won't cause your code to not compile, but it also expands the public interface of your class.
There's a few key points:
1. Classes should be thought of as exposing
functionality to a user, not
data to a user. These will often overlap, but the primary goal should be functionality. A toaster is not a metal box with resistors and a switch. A toaster is a device that toasts food to make it nice and crispy. I don't care that it uses a resistor or something to produce the burning.
2. Only exposing a public interface allows the maintainer of the class to change the private interface without breaking the code for a user of the class.
3. Only exposing a public interface disallows the user of the class from doing unintended things.
4. Also, data members cannot be polymorphic (virtual), but member functions (methods) can be.
For an example for (3), think about getting the size of a list.
https://en.cppreference.com/w/cpp/container/list/size
Let's imagine that size was just a public data member instead of being a method of list.
The user could do
my_list.size = 42;
. But... what should that do? You're not calling a function. The size of the list isn't actually 42. By making the actual data that holds the size of the list private, we prevent unwanted accessing of data that should only be manipulated internally by the class.