I have a couple questions I'm hoping someone could answer for me. I have many more videos to watch in your series thus far so I'm not sure if this was ever answered or even asked.
Header is obviously a ".h" file and I say "Body" meaning the ".cpp" file.
When including other headers, when do you know you should include it within another class header file or body file? What happens if they both include the file? Assuming I had a header file "foo.h," created another class with header file "bar.h" and body "bar.cpp"; when do you know to include "foo.h" in the header "bar.h" or body "bar.cpp" or does it really matter?
Another question I have is creating functions in the header, for example:
1 2 3 4 5 6 7 8 9 10 | // foo.h class FOO { public: int ID; void SetID(const int NewID){ ID = NewID; } int GetID() const{ return ID; } } |
When should you create functions in the body instead of the header? What if I was to put everything into the header, is that okay? What if all was in the body?
One last question regarding "const," which I had also written above. If the variable isn't a pointer does it really matter if you use const? For clarity:
1 2 3 4 5 6 7 8 9 10 | // this useless? const int GetID() const{ return ID; } // const only this? const int GetID() const{ return *ID; } // const this? int GetID() const{ return ID; } // does it really matter and I can just always use this? int GetID(){ return ID; } |
I hope my question aren't confusing and I thank anyone taking the time to help me out.