c++ - c++ 新手:函数返回类型的问题
问题描述
我对 c++ 很陌生,我正在尝试重现我教科书中写的程序。它的文本在下面,我已将其复制到在线 IDE 中。但是,我无法编译它,因为我得到下面引用的错误。
"error: functions that differ only in their return type
cannot be overloaded"
有关如何消除此错误的任何建议?我曾尝试查看相关问题的其他答案,但我不知道如何使它们适应我的情况。
先感谢您。
#include <iostream>
#include <cmath>
using namespace std;
int round(double number);
int main (){
double doubleValue;
char ans;
do
{
cout << "Enter a double value: ";
cin >> doubleValue;
cout << endl << endl;
cout << "Rounded that number is: " << round(doubleValue) << endl << endl;
cout << "Again? (y/n): ";
cin >> ans;
} while(ans == 'y' || ans == 'Y');
cout << "End of testing." << endl << endl;
return 0;
}
int round(double number){
return static_cast<int>(floor(number + 0.5));
}
解决方案
推荐阅读
- javascript - 在 Vue 的子级和父级中使用相同的组件
- react-native - Appcenter Android Build for React-Native with Unity
- javascript - 使用 API_URL 和私钥导入的 Hardhat 编译错误
- c# - System.Data.SqlClient 包引用不在项目引用之间流动
- testing - 出现测试错误“测试数据包含键‘类别’的字典值”
- amazon-web-services - 使用 Python 中的 Lambda 函数将 csv 文件从 S3 传输到 Kinesis Streams
- java - 更新查询以更新批量记录 mongodb
- python - 在 plotly 上设置视图窗口和轴
- c - 使用堆栈的迷宫中的老鼠
- typescript - 为什么 TypeScript 中没有自动导入/加载类?