//---------main.cpp------------
#include <iostream>
#include <string>
//继承包含 与 组合包含
using namespace std;
class Vehicle
{
};
class Motor
{
};
class Car :public Vehicle //继承包含
{
public:
Motor motor; //组合包含
};
void vehicleFn(Vehicle &v);
void motorFn(Motor &m);
int main(int argc,char **argv)
{
Car c;
vehicleFn(c); //OK 继承包含
motorFn(c); //错
motorFn(c.motor); //OK 组合包含
return 0 ;
}
1