So I have code that is a clock basically. In all of our assignments we need to name it pass(1-8).cpp This one is pass8.cpp. Part of the directions include this
"You should put the class prototype in Clock.h, and implement all the Clock member functions in Clock.cpp. In a third file, main.cpp, write the following code."
Then he says after that that we will compile it with g++ pass8.cpp Clock.cpp
I don't see what the point in the pass8.cpp file is if everything is already in the other three files. Can someone help me out with this as I don't have too much experience with .h files.
The idea here is that you want to do something like
1 2 3 4 5 6 7 8 9 10 11 12
// Clock.h
// #include guard -- prevents your header file from being #included multiple times
#ifndef CLOCK_H_INCLUDED_ORSOMEOTHERUNIQUENAMEOFYOURCHOICE
#define CLOCK_H_INCLUDED_ORSOMEOTHERUNIQUENAMEOFYOURCHOICE
class Clock
{
// Member variable/function declarations here
};
#endif
1 2 3 4 5 6 7 8 9 10
// Clock.cpp
#include "Clock.h"
// Whatever other #includes you might need
// Member function definitions here, e.g.
Clock::Clock()
{
// etc.
}
1 2 3 4 5 6 7 8 9
// main.cpp
#include "Clock.h"
// Whatever other #includes you need
int main()
{
// Use Clock here
}
That's how you would split everything into multiple files.