questions about header files and classes

i have a couple of stupid questions as a beginner. im taking a c++ class, and am working on classes right now. im having a big issue on figuring out how to properly set up getters and setters. the other thing im having a big issue with is the instructor is having us now set up the classes in header files, and im having issues getting anything from the header file to work in the main cpp file. can anyone help please?
im having a big issue on figuring out how to properly set up getters and setters.

Think carefully about needing them. Ideally, you wouldn't, and in non-ideal circumstances, the fewer the better.


im having issues getting anything from the header file to work in the main cpp file.

Don't forget to #include the header file, and if the actual class functions are in a separate file, don't forget to compile that and link to it.
Last edited on
i am, and as a example: #include "rational.h";, but part of the errors that come up include as if the header does not exist
#include "rational.h";
You shouldn't need that trailing semi-colon.


Does the header exist? Can the compiler find it? If you show the actual error message, we can address it.
Last edited on
the error messages that i am getting (multiple) are ones indicitive of the header file not existing, so i dont know if the compiler can find it, but it does exist, as part of the overall file. what i am doing is creating the header file first, then creating the main cpp file with the #include, and on this example thank you for the no semi colon needed
If the header file does exist, then you're not pointing the compiler at it properly.

Try giving the full include path i.e.

#include "C:\somePath\header.h"

If it finds it then, you know it's an include path problem.
even if they are a part of the same project?
even if they are a part of the same project?

Things like "projects" are your IDE hiding from you what's going on. When it breaks, you can't see that it's broken. The compiler doesn't know or care about "projects" - it only knows what the name of the header file is, and the list of places it's been told to search.
ok so far so good. thank you very much!
Topic archived. No new replies allowed.