Bug fix C4 class Foobar (#1143)

* Fixed bug in example code of C4 Expecptions. In C4, the class function void Foobar::foo(double x) is supposed to call the overloaded void Foobar::foo(int x), but in the call foo(std::round(x)), std::round returns a double. Hence, it will get stuck in an infinite recursive loop. Added static_cast<int>(..) to enforce the call to right overload. Added also keyword public to be more consistent.

* Changed static_cast<int> to narrow_cast<int> following ES.46.

* Modified C4 Foobar class, s.t, std::lround(x) is now called in
void foo(double) and the overload is changed to void foo(long) from (int). Now there is
no need for conversions.
This commit is contained in:
Ari Hietanen 2018-02-26 21:11:51 +02:00 committed by Andrew Pardoe
parent da3b6b98bc
commit 6c55d4eaaf

View File

@ -4081,8 +4081,9 @@ The language requires operators `=`, `()`, `[]`, and `->` to be members.
An overload set may have some members that do not directly access `private` data:
class Foobar {
void foo(int x) { /* manipulate private data */ }
void foo(double x) { foo(std::round(x)); }
public:
void foo(long x) { /* manipulate private data */ }
void foo(double x) { foo(std::lround(x)); }
// ...
private:
// ...