December 2021
Intermediate to advanced
352 pages
9h 32m
English
Trivial getters and setters are a hangover from the early days of C++. Typically, they look like this:
class x_wrapper
{
public:
explicit x_wrapper(int x_) : x(x_) {}
int get_x() const { return x; } // this is a getter
void set_x(int x_) { x = x_; } // this is a setter
private:
int x;
};
The get and set functions simply reach into the implementation of the class and return or modify the value. On the surface there are some things to commend in this approach. You can search your codebase for get_x and set_x to see where the code changes x. Alternatively, it is easy to set a breakpoint in the function so that you can trap every instance of where ...
Read now
Unlock full access