Skip to content

Replacing class with a function

Alexey Dmitriev edited this page Nov 11, 2018 · 1 revision

Suppose, you do not like having a class to represent a solution. You may replace it with a function.

In that case task.template might look like this:

void %ClassName%(std::istream& in, std::ostream& out) {
}

But the problem is that it will be called as solver.solve() from run.template and submission.template. It is indeed a problem, but not a big one: we will need to create solver that calls this function. So in run.template and submission.template we can replace old way of creating solver (%ClassName% solver;) to a new one:

class Solver {
    void solve(std::istream& in, std::ostream& out) {
        return %ClassName%(in, out);
    }
};
Solver solver;