Having a HAS_A Relationship - C++ Class

C++ examples for Class:Class Creation

Description

Having a HAS_A Relationship

class Vehicle {}; 
class Motor {}; 
class Car : public Vehicle 
{ 
  public: 
    Motor motor; 
}; 

void VehicleFn(Vehicle& v); 
void MotorFn(Motor& m); 

int main(int nNumberofArgs, char* pszArgs[]) 
{ 
    Car car; 
    VehicleFn(car);    // this is allowed 
    //MotorFn(car);      // this is not allowed 
    MotorFn(car.motor);// this is allowed 
    return 0; 
}

Related Tutorials