I am having a very hard time understanding classes. Why would I use a class? what are they for?
Classes are great for making OOP. You would make classes so that you can use the code again. I'm not great at explaining this though. Maybe one of the other guys can explain better.
Code:for (int i;;) { cout << "Smith"; }
Classes are basically a way of organizing your program.
They give you public/private/protected members so that you can have different parts of your program accessible to different callers (important for security, versioning, and cleanliness).
They give you a small unit of code that can be tested, reused (though that's usually a secondary concern - classes normally don't get reused all that much. That's what libraries and components are for), and shared.
They allow you to use OOP, so that you can inherit behaivor from other classes, change behaivor at runtime, and abstract out the behaivor from callers or dependents.
More or less, they're an attempt at solving the age old complexity problem in software by encapsulating data and the methods required to work on that data into a single object. Once a single object "owns" the data and the responsibility of managing it, it can be treated as a black box in most cases.
brackett explained it perfectly there.
The way I look at it in very general terms is that a class is a thing, an object, or a task etc etc - basically one object entails one "entity" in a program.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks