call the print_house_details function using the ptr_to_house variable
时间: 2024-01-14 22:03:54 浏览: 49
How-to-call-the-help-file.rar_The Call
To call the `print_house_details()` function using the `ptr_to_house` variable, you first need to create an instance of the `house` class and assign its address to `ptr_to_house`. Here's an example:
```
#include <iostream>
#include "house.h"
int main() {
// Create a new house object
house my_house("123 Main St", 3, 1998);
// Create a pointer to the house object
house* ptr_to_house = &my_house;
// Call the print_house_details function using the pointer
ptr_to_house->print_house_details();
return 0;
}
```
In this example, we create a `house` object called `my_house` with the location "123 Main St", 3 rooms, and built in 1998. We then create a pointer `ptr_to_house` and assign it the address of `my_house`. Finally, we call the `print_house_details()` function using the pointer and the arrow operator `->`. This will output:
```
Location: 123 Main St
Number of rooms: 3
Year built: 1998
```
阅读全文