, coding interview with binary tree depth-first search algorithm in C++, then a general C++ coding interview. Asked questions about pass by value, pass by reference etc. What is the difference between versions of C++. Polymorphism. Asked for writing code to implement methods. Gave me a class object, asked the role of each part of the code. I am attaching the code that asked me to fill in:
include <string>
#include <iostream>
#include <memory>
#include <cassert>
#include <vector>
enum class BuildType {
NORMAL, ACCELERATOR
};
class Builder {
/* write this class */
};
class NormalBuilder : public Builder {
/* write this class */
};
class AcceleratorBuilder : public Builder {
/* write this class */
};
std::unique_ptr<Builder> getBuilder(const BuildType aType) {
/* write this function */
}
class ModelObject {
public:
ModelObject(const BuildType aType,
const std::string& aName) :
_type(aType),
_name(aName) {}
void build() const {
auto builder = getBuilder(_type);
builder->build(_name);
}
private:
BuildType _type;
std::string _name;
};
int main() {
/*
* topModel (normal)
* |
* ---------------------------
* | |
* subModel1 (accelerator) subModel2 (accelerator)
*/
std::vector<ModelObject> objects;
objects.emplace_back(ModelObject(BuildType::NORMAL, "topModel"));
objects.emplace_back(ModelObject(BuildType::ACCELERATOR, "subModel1"));
objects.emplace_back(ModelObject(BuildType::ACCELERATOR, "subModel2"));
for (auto & obj : objects) {
obj.build();
}
}
Many questions they asked I forgot and could not practice before the interview. The answers were not on the top of my head as I learned C++ a decade ago and now implement it to solve problems in my research. I have no time to remember many definitions of C++ and no time to keep track of what's new coming to the next C++ version. They said they would let me know their decision by the next week.