Junior — Senior
Refactoring completion of a simple class
livecode
Task condition
Here is a program fragment that should print "true" or "false" to the standard output depending on the result returned by a method chosen in the code. Part of the refactoring has already been done, but it needs to be completed.
# include <memory>
# include <iostream>
# define ALL_RIGHT 0
class Entity;
class TaskExecutor {
public:
TaskExecutor() {
entityPtr_ = new Entity;
}
bool performTask() {
entityPtr_->callMethod();
// TODO: return the correct result
}
private:
Entity* entityPtr_;
};
int main() {
TaskExecutor executor;
auto result = executor.performTask();
std::cout << (result ? "true" : "false") << std::endl;
return ALL_RIGHT;
}
You need to fix the constructor and the performTask method, ensure proper management of dynamic memory, and guarantee that the program outputs the correct value.