I am relatively new to C++ and came accross something puzzling in my studies. In the book it says the point of good classes are their reusability. I am confused when it comes to the practice of writing the decleration in a header file and the definition in the .cpp file. Now the way I understand it is that if I want to reuse my classes in a different project I include the header files, but then I have to redefine all the class functions in that program. I think I am missing something but for the life of me I can't figure it out. Can anyone shed some light on this?
In the new project, you would link the object files of the old project together with including the headers.
But really, the point of object orientation isn't really reusability, but rather flexibility. Users can always use code that others write, be that code object oriented or not, and for the code writer himself reusable code isn't that useful either. Of course it's good when you already have a premade solution for your problem, but the thing is that normally code will undergo a number of changes after it's done, object orientation when applied correctly allows you to apply changes to your program like adding additional functionality without changing the original code at all.