The Fix-the-Bug Round
The previous lesson gave a procedure. This one runs it against the three archetypes these firms actually set, because the procedure is only convincing once you have watched it find something.
One: the leaking container
A hand-rolled vector, reported in this form at more than one firm. It grows correctly, indexes correctly, and leaks.
class Buffer {
public:
explicit Buffer(std::size_t n) : data_(new double[n]), size_(n) {}
~Buffer() { delete[] data_; }
double& operator[](std::size_t i) { return data_[i]; }
private:
double* data_;
std::size_t size_;
};
Step two of the procedure asks where the state is: a raw owning pointer. Step three asks for the invariant: data_ points to an array of size_ doubles that this object owns exclusively. Now scan for what breaks it, and the answer is not in the code shown, it is in the code that is absent.
The rest of this lesson is for subscribers
Unlock every lesson in Systems Programming for Trading, and every other premium course.
Subscribe to continueTest your knowledge
Keep reading Systems Programming for Trading
19 lessons in this course, and every other premium course, on one subscription.
- Every lesson in every course, with the worked examples and interactive simulators
- Graded questions on every lesson, with explanations for the wrong answers as well as the right one
- The trainers, timed assessments and brainteaser library that go with them