Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to ' ' is ambiguous

Tags:

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;
}
like image 234
damian Avatar asked Apr 01 '15 09:04

damian


1 Answers

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;
like image 74
poe123 Avatar answered Sep 17 '22 19:09

poe123