本关任务:编译时的多态,根据上下文代码,写出func函数的3个重载函数,使得输出为: value of x is 7 value of x is 9.132 value of x and y is 85, 64
时间: 2023-11-28 22:49:35 浏览: 76
以下是可能的实现:
```c++
#include <iostream>
using namespace std;
void func(int x) {
cout << "value of x is " << x << endl;
}
void func(double x) {
cout << "value of x is " << x << endl;
}
void func(int x, int y) {
cout << "value of x and y is " << x << ", " << y << endl;
}
int main() {
int x = 7;
double y = 9.132;
func(x);
func(y);
func(x, y);
return 0;
}
```
输出结果:
```
value of x is 7
value of x is 9.132
value of x and y is 7, 9
```
阅读全文