mirror of
https://github.com/iandinwoodie/cpp-design-patterns-for-humans.git
synced 2025-12-17 12:34:38 +03:00
Rolling back use of typedef with smart pointers.
This is to reduce the obfuscation of the code.
This commit is contained in:
@@ -35,7 +35,7 @@ class WoodenDoor : public Door
|
||||
class DoorFactory
|
||||
{
|
||||
public:
|
||||
static Door::ptr_t makeDoor(float width, float height)
|
||||
static std::shared_ptr<Door> makeDoor(float width, float height)
|
||||
{
|
||||
return std::make_shared<WoodenDoor>(width, height);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class DoorFactory
|
||||
int main()
|
||||
{
|
||||
// Make a door with dimensions 100x200.
|
||||
Door::ptr_t door = DoorFactory::makeDoor(100, 200);
|
||||
std::shared_ptr<Door> door = DoorFactory::makeDoor(100, 200);
|
||||
|
||||
// Output: width = 100
|
||||
std::cout << "width = " << door->getWidth() << std::endl;
|
||||
@@ -52,7 +52,7 @@ int main()
|
||||
std::cout << "height = " << door->getHeight() << std::endl;
|
||||
|
||||
// We can use the factory again to make a door with dimensions 50x100.
|
||||
Door::ptr_t door2 = DoorFactory::makeDoor(50, 100);
|
||||
std::shared_ptr<Door> door2 = DoorFactory::makeDoor(50, 100);
|
||||
|
||||
// Output: width = 50
|
||||
std::cout << "width = " << door2->getWidth() << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user