From the course: Object-Oriented Programming with C++

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Separating class declaration from class definition

Separating class declaration from class definition - C++ Tutorial

From the course: Object-Oriented Programming with C++

Separating class declaration from class definition

- [Instructor] Since our class is very basic, we could keep it in one CPP file. However, a larger class is usually split between a header file for the declaration and the CPP file for the implementation part. Declaring a class means specifying its structure without providing the implementation details. Let me quickly show you how this would look in practice. So here's the folder of our review.cpp file, and we'll create a new header file, review.h. The declaration goes in this header file. Let's switch to the initial code and copy this entire class. We'll keep the member variables and the function prototype, but trim out the actual implementation of the displayDetails function. Next, I'll add a header guard to ensure that the contents of this header file are included only once, even if they are referenced redundantly in multiple files. Ifndef, and I will give it a unique name, and we end it. So this is a common route of errors in large projects, where the same header is included in…

Contents