adding the curly braces
This commit is contained in:
@@ -254,8 +254,9 @@ Note: We’ve 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
|
||||||
|
|||||||
Reference in New Issue
Block a user