help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function call misinterpreted as a variable


From: Jaspreet
Subject: Re: function call misinterpreted as a variable
Date: 3 Oct 2005 07:45:11 -0700
User-agent: G2/0.2

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
>
> I've gone over the code several times line by lin, and my eyes are
> starting to bleed.  It looks totally fine to me, and I'm actually
> wondering whether I found a compiler bug, but more likely some weird
> feature, or I'm just totally missing something.  And before anyone asks,
> yes it is homework, but I am trying to grade it, not do it.  my version
> of GCC (as reported by its man page) is 4.0.1   2005-07-11 and I am
> running debian testing, kernel version 2.6.8-1-386 #1
>
[snip program]

I get the following error using g++. I guess its self explanatory:

rt.cc: In function `int main()':
rt.cc:27: use of `plus' is ambiguous
rt.cc:5:   first declared as `double plus(double, double, double)' here
/usr/include/c++/3.2.2/bits/stl_function.h:128:   also declared as `
   template<class _Tp> struct std::plus' here
rt.cc:27: use of `plus' is ambiguous
rt.cc:5:   first declared as `double plus(double, double, double)' here
/usr/include/c++/3.2.2/bits/stl_function.h:128:   also declared as `
   template<class _Tp> struct std::plus' here

There is a plus function in stl_function.h and one in your code. So,
the compiler cannot determine which function needs to be called.

Now thats the problem with using namespace std. If you remove the
'using namespace std' and explicitly add std to calls to cout and cin,
then your program would compile properly.

I guess there's a point in C++ FAQs which focuses on why usage of
namespace may cause a compile time error.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]