adding the curly braces

This commit is contained in:
Jidong Xiao
2023-12-01 01:28:17 -05:00
parent 400acaae68
commit f0ddee4c85

View File

@@ -254,8 +254,9 @@ Note: Weve used the same pointer variable (p_ptr) to point to objects of two
```cpp ```cpp
double area = 0; double area = 0;
for (std::list<Polygon*>::iterator i = polygons.begin(); i!=polygons.end(); ++i) for (std::list<Polygon*>::iterator i = polygons.begin(); i!=polygons.end(); ++i){
area += (*i)->Area(); area += (*i)->Area();
}
``` ```
Which Area function is called? If *i points to a Triangle object then the function defined in the Triangle 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 ```cpp
int count = 0; int count = 0;
for (std::list<Polygon*>::iterator i = polygons.begin(); i!=polygons.end(); ++i) for (std::list<Polygon*>::iterator i = polygons.begin(); i!=polygons.end(); ++i){
count += (*i)->IsSquare(); count += (*i)->IsSquare();
}
``` ```
If Polygon::IsSquare had not been declared virtual then the function defined in Polygon would always be If Polygon::IsSquare had not been declared virtual then the function defined in Polygon would always be