Skip to content

Instantly share code, notes, and snippets.

@krvajal
Last active January 9, 2018 19:48
Show Gist options
  • Save krvajal/39d9d7b010d7d2e9bb5692b3c331c267 to your computer and use it in GitHub Desktop.
Save krvajal/39d9d7b010d7d2e9bb5692b3c331c267 to your computer and use it in GitHub Desktop.
/// Requirement: print the area of the given shape
void print_area(const Shape &shape)
{
std::cout << shape.get_area() << std::endl;
}
int main(){
std::vector<std::unique_ptr<Shape>> shapes;
shapes.push_back(std::make_unique<Circle>(10));
shapes.push_back(std::make_unique<Circle>(11.0));
shapes.push_back(std::make_unique<Rectangle>(10.0, 20.0));
shapes.push_back(std::make_unique<Rectangle>(1.0, 0.5));
for (auto &s : shapes)
{
print_area(*s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment