#ifndef CAR_HPP #define CAR_HPP class Car { public: virtual void startEngine(); <-- 1 // ... protected: bool isRunning_; bool radioOnAM_; int radioFreq_; }; #endif
Here is an example of the source file Car.cpp: #include "Car.hpp" <-- 1 void Car::startEngine() <-- 2 { isRunning_ = true; // ... }
The line void Car::startEngine() tells the compiler that this is the definition of the startEngine() member function from the Car class. If this just said void startEngine() { ... } the compiler would think that a non-member function was being defined, as opposed to the startEngine() member function of the Car class. The line isRunning_ = true; sets the protected: data member isRunning_ to true. If Car a; a.startEngine(); has been executed, this line would set a.isRunning_ to true (even though a.isRunning_ is protected: it does exist and can be accessed by member functions of the Car class). |