首页 > 解决方案 > 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));

}

标签: c++function

解决方案


推荐阅读