<<< C++ struct | Index | C++ struct initialization >>> |
With set_dimensions() and area() member functions added to
the Rectangle struct, the main() function can be re-written as follows:
int main() { Rectangle rect { 20, 10 }; std::cout << "rectangle width: " << rect.width << '\n'; std::cout << "rectangle height: " << rect.height << '\n'; std::cout << "rectangle area: " << rect.area() << '\n'; rect.set_dimensions( 44, 33 ); std::cout << "updated rectangle width: " << rect.width << '\n'; std::cout << "updated rectangle height: " << rect.height << '\n'; std::cout << "updated rectangle area: " << rect.area() << '\n'; return 0; }
<<< C++ struct | Index | C++ struct initialization >>> |