I am new to programming, and am having trouble getting my head around classes.
Hypothetically I want to create a database for a gym, I want to be able to add new members whenever one joins.
I believe from what I have read that a class would be needed as all members will need the same information entered albeit different values. How do I create a class where I can have user defined information.
I hope this makes sense.
I am teaching myself using c++ primer, you tube and now this forum, so please be patient.
Have you studied structs? If not, you should do so first.
A class is simply a struct, with the difference that members are by default private unless declared otherwise, while struct members are by default public.
I have looked at structs, but I was lead to believe that they are used more in c programming and that classes are a super structure so to speak. Having said that I shall now study structs. Thank you.
I was lead to believe that they are used more in c programming
structs were originally a C feature. structs are used in C++ both for backward compatability with C and are most often used to represent POD (Plain Old Data) objects in C++.
classes are a super structure so to speak.
C++ extended C's implementation of structs to support visibility (public, protected, private) along with methods (including constructors and destructors). Features which are more commonly associated with classes but apply to both structs and classes. So there is a difference in functionality between C and C++ structs.
As far as I know structs are kind of just records of data, whereas classes are meant to actually model objects of the real world. The conceptual difference is pretty big, even though some classes could be implemented as structs. In your case, a struct would allow you to store all the data about the members. But if you want to associate the re-newal of membership with the members, making it a capability of a member, you need a class. The reason is that then you need a method which allows a member object (an object is a concrete instance of a class, in your case a concrete member whereas the class would be the description of the general properties and capabilities of a member). In C++ methods are called functions I think, but the concept is the same. Member functions of a C++ object are roughly the same as methods of a Java object (I know more about Java that's why I write method often when it should be function in C++).