diff --git a/README.md b/README.md index 5263d16..01c1918 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ C++11 includes the following new language features: - [range-based for loops](#range-based-for-loops) - [special member functions for move semantics](#special-member-functions-for-move-semantics) - [converting constructors](#converting-constructors) +- [explicit conversion functions](#explicit-conversion-functions) C++11 includes the following new library features: - [std::move](#stdmove) @@ -975,6 +976,26 @@ A c = {0, 0}; // calls A::A(std::initializer_list) A d{0, 0, 0}; // calls A::A(std::initializer_list) ``` +### Explicit conversion functions +Conversion functions can now be made explicit using the `explicit` specifier. +```c++ +struct A { + operator bool() const { return true; } +}; + +struct B { + explicit operator bool() const { return true; } +}; + +A a{}; +if (a); // OK calls A::operator bool() +bool ba = a; // OK copy-initialization selects A::operator bool() + +B b{}; +if (b); // OK calls B::operator bool() +bool bb = b; // error copy-initialization does not consider B::operator bool() +``` + ## C++11 Library Features ### std::move