mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
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:
parent
da3b6b98bc
commit
6c55d4eaaf
|
@ -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:
|
||||
// ...
|
||||
|
|
Loading…
Reference in New Issue
Block a user