Topic: bug in gnu std including <string> & <vector>?


Author: Richard Sperko <sperk@execpc.com>
Date: 1997/12/11
Raw View
Hello,

I cannot get this bit of code to compile, it complains about ambiguous
operators.  I am using g++ ver 2.7.2.3, and libg++ ver 27.1.4, on a
Linux box kernel ver 2.0.30.

Am I doing something wrong?  Why are the templates in function.h being
called at all?

-- cut here --
#include <string>
#include <vector>

void main()
{
        string dog = "Dog";
        string cat = "Cat";

        if( dog != cat )
                dog = cat;
}
-- cut here --

I would really appreciate any help on this.

Sincerly,
Rick Sperko
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Oleg Zabluda <zabluda@math.psu.edu>
Date: 1997/12/12
Raw View
Richard Sperko <sperk@execpc.com> wrote:
: Hello,

: I cannot get this bit of code to compile, it complains about ambiguous
: operators.  I am using g++ ver 2.7.2.3, and libg++ ver 27.1.4, on a
: Linux box kernel ver 2.0.30.

: Am I doing something wrong?

No. Well, except having void main(). g++ just doesn't do overload
resolution of template functions right. You should either reverse
the order of the inclusion, or use <String.h>, or something like
that, to make g++ compile it. egcs-2.90.16 (pre-g++-2.8.0) compiles
this.

: Why are the templates in function.h being
: called at all?


: -- cut here --
: #include <string>
: #include <vector>

: void main()
: {
:         string dog = "Dog";
:         string cat = "Cat";

:         if( dog != cat )
:                 dog = cat;
: }

Oleg.
--
Life is a sexually transmitted, 100% lethal disease.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Stefan Rupp <struppi@gia.rwth-aachen.de>
Date: 1997/12/12
Raw View
Good morning,

Richard Sperko <sperk@execpc.com> writes:
> I cannot get this bit of code to compile, it complains about ambiguous
> operators.  I am using g++ ver 2.7.2.3, and libg++ ver 27.1.4, on a
> Linux box kernel ver 2.0.30.

RTFFAQ!

The URL http://www.cygnus.com/misc/g++FAQ.html#SEC49 covers exactly
this problem.  As a workaround use

   if ( ! ( dog == cat ) )

instead of

   if ( dog != cat )

BTW: In C++ the main() function has return type int, not void.

Ciao,
     struppi

--
Stefan H. Rupp  (struppi@acm.org)         Tel.: +49 241 80-5295 (dienstl.)
Geodaetisches Institut der RWTH Aachen          +49 241 25209   (privat)
Templergraben 55, D-52062 Aachen, Germany       +49 172 2615235 (D2)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Jason Merrill <jason@cygnus.com>
Date: 1997/12/13
Raw View
>>>>> Richard Sperko <sperk@execpc.com> writes:

> I cannot get this bit of code to compile, it complains about ambiguous
> operators.  I am using g++ ver 2.7.2.3, and libg++ ver 27.1.4, on a
> Linux box kernel ver 2.0.30.

> Am I doing something wrong?  Why are the templates in function.h being
> called at all?

You aren't.  g++ 2.7.2 doesn't support partial ordering of function
templates, and those two headers don't play well together as a result.
This particular problem is covered in the gnu.g++.help FAQ.

The g++ in egcs-1.0 (http://www.cygnus.com/egcs/) and the
soon-to-be-released gcc-2.8.0 do support partial ordering, and have no
problems with your testcase.

Jason
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]