From f0ddee4c8563f7ce5fa29bb00b9dd1d0bac181ca Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Fri, 1 Dec 2023 01:28:17 -0500 Subject: [PATCH] adding the curly braces --- lectures/26_inheritance/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lectures/26_inheritance/README.md b/lectures/26_inheritance/README.md index bd83ec7..56e04d9 100644 --- a/lectures/26_inheritance/README.md +++ b/lectures/26_inheritance/README.md @@ -254,8 +254,9 @@ Note: We’ve used the same pointer variable (p_ptr) to point to objects of two ```cpp double area = 0; -for (std::list::iterator i = polygons.begin(); i!=polygons.end(); ++i) -area += (*i)->Area(); +for (std::list::iterator i = polygons.begin(); i!=polygons.end(); ++i){ + area += (*i)->Area(); +} ``` Which Area function is called? If *i points to a Triangle object then the function defined in the Triangle @@ -265,8 +266,9 @@ class would be called. If *i points to a Quadrilateral object then Quadrilateral ```cpp int count = 0; -for (std::list::iterator i = polygons.begin(); i!=polygons.end(); ++i) -count += (*i)->IsSquare(); +for (std::list::iterator i = polygons.begin(); i!=polygons.end(); ++i){ + count += (*i)->IsSquare(); +} ``` If Polygon::IsSquare had not been declared virtual then the function defined in Polygon would always be