Seneca BTP 305
Creating the FoodOrder Header
Lab 1To begin this section, create a new class in Visual Studio. This will automatically generate both the .h and .cpp files for you.
Right-click on your project name, then select Add > Class. In the Class Name field, enter FoodOrder, and click OK.
Visual Studio should now create two files: FoodOrder.h and FoodOrder.cpp.
We’ll start by writing the full class definition inside FoodOrder.h, and then move on to FoodOrder.cpp next.
Guarding The Class
Before writing our class, we need to protect it from being defined more than once. This is done using header guards, which prevent duplicate definitions when a header file is included multiple times in a project.
Here’s how to set it up in your FoodOrder.h file:
#ifndef SENECA_FOODORDER_H
#define SENECA_FOODORDER_H
class FoodOrder
{
};
#endifHere’s what’s happening:
#ifndefmeans if not defined. It checks whetherSENECA_FOODORDER_Hhas already been defined.If it hasn’t, the code between
#ifndefand#endifruns.#define SENECA_FOODORDER_Hmarks it as defined so the next time this file is included, the compiler skips it.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 17 more lessons in Seneca BTP 305.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.