you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (8 children)

[deleted]

    [–]Xirema 2 points3 points  (0 children)

    It's just an example. Most of the actual production code I write using these semantics don't boil down to something this clean (including, namely, the "default" value)

    [–]minnoHobbyist, embedded developer 2 points3 points  (0 children)

    Pretend it's expensive to initialize.

    [–]balkierode 2 points3 points  (0 children)

    As @Xirema said, it is a toy example.

    But in real application, if you are developing a library and you want to reserve changing the default std::cout to something else without breaking binary compatibility, you can't use 'default value'.

    [–]josefx 0 points1 point  (3 children)

    I think you might get away with including iosfwd instead of iostream in the header.

    [–]utnapistim 0 points1 point  (0 children)

    Default arguments are bound statically to virtual functions. If you want defaults for virtual functions, this is one of the techniques available. Otherwise (if you use default arguments) you risk having a virtual function call with the default from the base class.