C++ Class Inheritance Has A Relationship

Description

C++ Class Inheritance Has A Relationship

class Vehicle {}; 
class Motor {}; /*from   ww w .  j av  a 2s.  c  o  m*/
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; 
}



PreviousNext

Related