4 ms·
To me the original sin of the example is not to perform the calculation in the constructor. The third version, the one with the "int count() const" method and w
by jerome-jh 6y ago
To me the original sin of the example is not to perform the calculation in the constructor. The third version, the one with the "int count() const" method and without the h and w members, is perfectly valid and (correct me if I'm wrong) thread-safe. It is a bit longer than the 'functional' implementation but does handle memoization. This is basically the C++ way to make a 'closure'.
The point is certainly valid, but the example could have been more carefully chosen.