CJCoding With Joseph
15free / daySign inCreate account

Seneca BTP 305

Creating the FoodOrder Header

Lab 1

To 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
{
};

#endif

Here’s what’s happening:

  • #ifndef means if not defined. It checks whether SENECA_FOODORDER_H has already been defined.

  • If it hasn’t, the code between #ifndef and #endif runs.

  • #define SENECA_FOODORDER_H marks it as defined so the next time this file is included, the compiler skips it.

Members only

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.