carfactory.cpp

来自「C++高级编程这本书所附的源代码」· C++ 代码 · 共 32 行

CPP
32
字号
/**
 * CarFactory.cpp
 */

#include "CarFactory.h"

// Initialize the count to zero when the factory is created.
CarFactory::CarFactory() : mNumCarsInProduction(0) {}

// Increment the number of cars in production and return the 
// new car.
Car* CarFactory::requestCar()
{
  mNumCarsInProduction++;
  return createCar();
}

int CarFactory::getNumCarsInProduction() const
{
  return mNumCarsInProduction;
}

Car* FordFactory::createCar()
{
  return new Ford();
}

Car* ToyotaFactory::createCar()
{
  return new Toyota();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?