Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

How it works...

In this recipe, we will learn how to implement the decorator pattern. To start, let's look at a simple example: suppose we are writing a C++ application that will host a website. In our website, we need to define a button that users can click on, but we need to calculate the width of the button given an extra margin that adds to the total size of the button:

class margin{public:    int width()    {        return 32;    }};

As shown in the preceding, we have created a class called margin that returns the width of the margin in question (we will only focus on the width to simplify our example). We can then define our button as follows:

class button : public margin{public:    int width()    {        return margin::width() + 10;    }};

As shown in the preceding ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content