gpt4 book ai didi

c++ - 对 ' ' 的引用不明确

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:00 24 4
gpt4 key购买 nike

很抱歉,我不知道为什么这个算法不起作用。编译时的错误是:“Reference to 'function' is ambiguous”并且在 y = function() 行,我调用函数的地方

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.141
float function(int g, int m, int s, float z)
{
using namespace std;
z = (g + m/60.0 + s/3600.0)*PI/180.0;
return z;
}
int main()
{
using namespace std;

float y;
int g,m,s;

cout << "g = ";
cin >> g;
cout <<"m = ";
cin >> m;
cout<<"s= ";
cin >>s;

y = function();
cout << "y= " << y << endl;
//cout<< (g + m/60.0 + s/3600.0)*PI/180.0 << endl;
return 0;
}

Vers2 - 更新:

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.141
float function(int g, int m, int s)
{
//using namespace std;
float z = (g + m/60.0 + s/3600.0)*PI/180.0;
//std::cout << z <<std::endl;
return z;
}
int main()
{
// using namespace std;

float y;
int g,m,s;

std::cout << "g = ";
std::cin >> g;
std::cout <<"m = ";
std::cin >> m;
std::cout<<"s= ";
std::cin >>s;

function();
// std::cout << "y= " << y << std::endl;
//cout<< (g + m/60.0 + s/3600.0)*PI/180.0 << endl;
return 0;
}

最佳答案

std 中有一个成员 function,您将其插入到您的命名空间中。避免使用 using namespace std;;您可以通过这种方式导入您需要的内容:

using std::cout;
using std::cin;

关于c++ - 对 ' ' 的引用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29387600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com