C++ – Reference to ‘ ‘ is ambiguous

c

I am sorry but i don't know why this algorithm is not working.
The error at compiling is : "Reference to 'function' is ambiguous " and is on y = function() line, where I am calling the 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 – updated:

#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;
}

Best Answer

There is a member function in std and you inserted it into your namespace. Avoid using using namespace std;; you can import what you need this way:

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