Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edits & Suggestions for Events Chapter #1

Merged
merged 21 commits into from
Jul 6, 2017
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions chapters/events/chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,23 +916,21 @@ You can have static ofEvents. This can become useful in several situations. Take

**MH: I think you can get away with a brief explanation and then point them towards the example.**

## The Rule of 3 (or 5)

## THE RULE OF 3 (or 5)
In C++ there is a rule, called the rule of 3, which became the rule of 5 in C++11.
Read about it [here](https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)).
In short it says that if you add to a class any of the following you must add them all.
In C++ there is a rule, called the rule of 3, which became the rule of 5 in C++11. Read about it [here](https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)). In short, it says that if you one of the following methods to a class, you must add all of them:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should say:
In short, it says that if you add one of the following methods to a class, you must add all of them:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops - sorry about that


* destructor `~ClassName(){...}`
* copy constructor `ClassName(ClassName& other)`
* copy assignment operator `ClassName& operator=(ClassName& other)`
* move assignment operator (C++11 only) `ClassName& operator=(ClassName&& other)`
* move constructor (C++11 only) `ClassName(ClassName&& other)`

So, in order to have exception-safe code you must follow this rule.
So, in order to have exception-safe code you must follow this rule. When listening to any `ofEvent` in your custom classes, it is a good idea to stop listening to these when the class instance is destroyed. This means that you will declare the class destructor, and hence, you'll have to follow this rule.

When listening to any `ofEvent` in your custom classes, it is a good idea to stop listening to these when the class instance is destroyed. This means that you will declare the class destructor, hence you'll have to follow this rule.
Even if you don't follow this rule, your code will compile with no errors or warnings, and it will probably work well, but it will not be exception-safe, and you run the risk of having several undesired side-effects, which can be really hard to debug.

Even if you don't follow this rule, your code will compile with no errors or warnings and it will probably work well, but it will not be exception-safe, and you run the risk of having several undesired side-effects, which can be really hard to debug.
**MH: it would be good to add a note with a concrete example that might arise if you declare a destructor without the other 4...**



Expand Down Expand Up @@ -1011,4 +1009,3 @@ For example, the previous code using a lambda function as the callback would be:
ofEventListener listener;

};