Add example for explicit conversion operators

This commit is contained in:
Jason Turner
2016-05-24 22:20:03 -06:00
parent 51ca655e8d
commit 01ab3b9fa5

View File

@@ -349,6 +349,23 @@ Instead mark single parameter constructors as `explicit`, which requires them to
Similarly to single parameter constructors, conversion operators can be called by the compiler and introduce unexpected overhead. They should also be marked as `explicit`.
```cpp
//bad idea
struct S {
operator int() {
return 2;
}
};
```
```cpp
//good idea
struct S {
explicit operator int() {
return 2;
}
};
```
## Consider the Rule of Zero