|
From: | Zara |
Subject: | Re: function call misinterpreted as a variable |
Date: | Mon, 03 Oct 2005 10:39:35 GMT |
User-agent: | Thunderbird 1.4 (Windows/20050908) |
Kyle wrote:
Zara wrote:sjbrown8@eng.usf.edu wrote:I have the piece of code below, and when i try compiling with the line g++ 753075304.cpp I get the following error message: 753075304.cpp: In function 'int main()': 753075304.cpp:29: error: 'plus' was not declared in this scope(...)#include <iostream> using namespace std; #include <cmath> double quad(double, double, double); double plus(double, double, double); double neg(double, double, double); int main() { double xpos; double a; double b; double c; double square; double xneg; cout << "This program will compute a quadratic equation\n"; cout << "Please enter a number: \n"; cin >> a; cout << "Please enter another number: \n"; cin >> b; cout << "Please enter a final number: \n"; cin >> c; square = quad(a,b,c); xneg = neg(a,b,square); xpos = plus(a,b,square); cout << "The positive function is: " << xpos << "\n"; cout << "The negative function is: " << xneg << "\n"; return 0; }(...)
(...)
seems unlikely to me that its a bug, as Comeau is giving following error for that codeYes, you are right, I would not bet myself. I have tried with Comeau, and you are right."ComeauTest.c", line 27: error: "plus" is ambiguous xpos = plus(a,b,square);Comeau could by buggy as well, but i wouldnt bet on it(, at last without long session with standard and rules of lookup and function choosing)
So, I have looked at the conflicting part: <stl_function.h> template <class _Tp> struct plus : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
}; So there is the problem: The compiler is unable to decide if we want: double plus(double,double,double) or double plus<double>::operator()(double,double,double)In this case, it is not trying to decide between overloaded functions, but between two pretty different ways to interpret the statement. And we may suppose Comeau is right, as usual.
Regards
[Prev in Thread] | Current Thread | [Next in Thread] |