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: Zara
Subject: Re: function call misinterpreted as a variable
Date: Mon, 03 Oct 2005 09:20:19 GMT
User-agent: Thunderbird 1.4 (Windows/20050908)

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;
}
(...)

I tried to compile it with GCC 3.4.2, adn it also failed.
The problem lies in a existing template version of plus in std namespace. I think it is a GCC bug, because AFAIK the compiler *should* prefer non-template functions, but anyhiw, there is a workaround:

substitute your line
  using namespace std;
with these two lines
  using std::cin;
  usign std::cout;

In general, you should try to limit your using clauses to specific classes or functions, avoiding using complete namespaces.

Best regards


reply via email to

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