The Train
Implementation File
In this part of the assignment, you'll write function stubs for the Train
member functions. Again, our goal is to get a correct skeleton of what the implementation will eventually look like without worrying about the implementation details at the moment.
Implementation Steps
Create the Train
Implementation File and Stub Out Functions
Create a file named train.cpp
, and then create stubs for each of the functions you declared in train.hpp
for the Train
class. You'll follow basically the same process you did for car.cpp
; namely,
- Include the necessary header files.
- Write stub functions for all
Train::
functions. - Implement the
operator<<
function forTrain
objects, calling yourTrain
'sprintToStream
function.
Try Compiling Your Skeleton Train
Class!
Skeleton train? That's spooky!
Oh, hush…
Ooh, looks like our dialogue got a little bit of… Pumpkin spice.
Before you try compiling, add the following temporary code to the top of car.cpp
:
// Disable warnings that happen because our stubs don't do anything yet.
#pragma GCC diagnostic ignored "-Wunused-private-field" // FIXME: Remove soon.
#pragma GCC diagnostic ignored "-Wunused-parameter" // FIXME: Remove soon.
Now you should be able to compile your Train
class, even though it doesn’t do anything yet.
clang++ -Wall -std=c++17 -c train.cpp -o train.o
If your code is correct, you shouldn't get any errors or warnings. If you do have errors or warnings, fix them before moving on.
Because the Train
class uses the Car
class (by including the car.hpp
header file), you might need to go back and fix code in your Car
class header file before everything compiles nicely.
After completing this step, everything you've written should still compile!
(When logged in, completion status appears here.)