Struggling with classes.........

Howdy folks....

I'm struggling to get my head around classes, specifically what's being taught in this lesson:
http://www.learncpp.com/cpp-tutorial/89-class-code-and-header-files/

Actually, i already put a question at the bottom of that page, and i'm copying also here, i'm hoping someone could set me straight on this!

Here's my question to the author of that page on learncpp.com:

----------------

I’m really failing to understand this chapter.

I don’t understand the difference between class "definition" and "implementation".

Your "class Date" example is actually longer (32 lines) then the original (26 lines) and i don’t see the benefit. Are the functions that are moved outside now placed in "int main()"?

To use the functionality of the class, you don’t need to look inside it at all do you? Isn’t that all done from "int main()"???

I don’t see the reason to move anything outside. I thought the benefits of classes (mentioned earlier) is that they package things up nicely and keep stuff out of sight, but in this lesson you’re recommending un-packaging them again!!

Same thing with the "class Calc" example, the original seems nice and compact, the second version seems a lot longer and harder to read.

I’m sure i’m just not getting something fundamental here. If possible, could you give a clear explanation of the difference between class "definitions" and "implementations"?
Last edited on
In keeping with the principle of encapsulation, the implementations(.cpp file) is kept separate from the interface(.h file) for an abstract data type. As a result, you don't have to scroll through tons of code just to look through different types of methods. You also abstract away the implementation, so that the client only needs to know what the method does and not how it works.
Last edited on
Thanks for taking the time.......

I understand the concept of what your saying but not the specifics.

I guess what I need is to see some examples, then I can work it out for myself.

Does anyone have a link to some classes that shows this (in a relatively simple way) in action?

Or code post some code and point out the implementation, the method, the definition, the interface?

Am I right in thinking that third party libraries are basically just a collection of classes that have been separated out in the way Mr Chicken described?
closed account (48T7M4Gy)
https://www3.ntu.edu.sg/home/ehchua/programming/cpp/cp3_OOP.html
Thanks for the link, that looks useful, gonna work my way through it.............
Topic archived. No new replies allowed.