www.digitalmars.com         C & C++   DMDScript  

c++ - Error: ambiguous reference to symbol

reply "Alex Vinokur" <alexvn connect.to> writes:
===========================================
Digital Mars C/C++ Compiler Version 8.40.2n
===========================================


DMC has a problem with the following program.

====== C++ code : File foo.cpp : BEGIN ======

#include <string>
using namespace std;

template <class T>
int operator!=(const T& x, const T& y)
{
  return !(x == y);
}

int main ()
{
const string str;
  return 0;
}

====== C++ code : File foo.cpp : END ========

====== Compilation : BEGIN ======

$ dmc -I. -IC:/dm/stlport/stlport foo.cpp

C:/dm/stlport/stlport\stl/_algobase.c(221) : Error: ambiguous reference to
symbol
Had: operator !=(const T&,const T&)
and: std::operator !=(const _Tp&,const _Tp&)
C:/dm/stlport/stlport\stl/_algobase.c(234) : Error: ambiguous reference to
symbol
Had: operator !=(const T&,const T&)
and: std::operator !=(const _Tp&,const _Tp&)
C:/dm/stlport/stlport\stl/_algobase.c(235) : Error: ambiguous reference to
symbol
Had: operator !=(const T&,const T&)
and: std::operator !=(const _Tp&,const _Tp&)
C:/dm/stlport/stlport\stl/_algobase.c(240) : Error: ambiguous reference to
symbol
Had: operator !=(const T&,const T&)
and: std::operator !=(const _Tp&,const _Tp&)
C:/dm/stlport/stlport\stl/_string.c(392) : Error: ambiguous reference to symbol
Fatal error: too many errors
--- errorlevel 1

====== Compilation : END ========


--
   Alex Vinokur
     mailto:alexvn connect.to
     http://mathforum.org/library/view/10978.html
Mar 18 2004
next sibling parent "Anton Sekeris" <no.spam inter.nl.net> writes:
Walter,

Alex' problem might be stemming from the same issue as the one I
reported in C++.beta under subject 'namespace bug?' on 2004/02/18.

Kind regards,
Anton Sekeris.


Alex Vinokur wrote:

 
 ===========================================
 Digital Mars C/C++ Compiler Version 8.40.2n
 ===========================================
 
 
 DMC has a problem with the following program.
 
 ====== C++ code : File foo.cpp : BEGIN ======
 
 #include <string>
 using namespace std;
 
 template <class T>
 int operator!=(const T& x, const T& y)
 {
   return !(x == y);
 }
 
 int main ()
 {
 const string str;
   return 0;
 }
 
 ====== C++ code : File foo.cpp : END ========
 
 ====== Compilation : BEGIN ======
 
 $ dmc -I. -IC:/dm/stlport/stlport foo.cpp
 
 C:/dm/stlport/stlport\stl/_algobase.c(221) : Error: ambiguous
 reference to symbol Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_algobase.c(234) : Error: ambiguous
 reference to symbol Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_algobase.c(235) : Error: ambiguous
 reference to symbol Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_algobase.c(240) : Error: ambiguous
 reference to symbol Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_string.c(392) : Error: ambiguous reference
 to symbol Fatal error: too many errors
 --- errorlevel 1
 
 ====== Compilation : END ========
 
 
 --
    Alex Vinokur
      mailto:alexvn connect.to
      http://mathforum.org/library/view/10978.html
Mar 18 2004
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
The problem is there's a template in std which matches the template you
defined in the global namespace. By bringing std's symbol table into the
global namespace, then there's a conflict. This is not a bug in DMC++.

"Alex Vinokur" <alexvn connect.to> wrote in message
news:c3c9cn$aov$1 digitaldaemon.com...
 ===========================================
 Digital Mars C/C++ Compiler Version 8.40.2n
 ===========================================


 DMC has a problem with the following program.

 ====== C++ code : File foo.cpp : BEGIN ======

 #include <string>
 using namespace std;

 template <class T>
 int operator!=(const T& x, const T& y)
 {
   return !(x == y);
 }

 int main ()
 {
 const string str;
   return 0;
 }

 ====== C++ code : File foo.cpp : END ========

 ====== Compilation : BEGIN ======

 $ dmc -I. -IC:/dm/stlport/stlport foo.cpp

 C:/dm/stlport/stlport\stl/_algobase.c(221) : Error: ambiguous reference to
symbol
 Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_algobase.c(234) : Error: ambiguous reference to
symbol
 Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_algobase.c(235) : Error: ambiguous reference to
symbol
 Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_algobase.c(240) : Error: ambiguous reference to
symbol
 Had: operator !=(const T&,const T&)
 and: std::operator !=(const _Tp&,const _Tp&)
 C:/dm/stlport/stlport\stl/_string.c(392) : Error: ambiguous reference to
symbol
 Fatal error: too many errors
 --- errorlevel 1

 ====== Compilation : END ========


 --
    Alex Vinokur
      mailto:alexvn connect.to
      http://mathforum.org/library/view/10978.html
Mar 18 2004
parent reply "Alex Vinokur" <alexvn connect.to> writes:
"Walter" <walter digitalmars.com> wrote in message
news:c3du2o$4tn$2 digitaldaemon.com...
 The problem is there's a template in std which matches the template you
 defined in the global namespace. By bringing std's symbol table into the
 global namespace, then there's a conflict. This is not a bug in DMC++.
[snip] So, what to do? P.S. GNU g++ 3.3.1, Microsoft C++ 13.00.9466, Borland C++ 5.5.1 have no problem with that code. -- Alex Vinokur mailto:alexvn connect.to http://mathforum.org/library/view/10978.html
Mar 18 2004
parent "Walter" <walter digitalmars.com> writes:
"Alex Vinokur" <alexvn connect.to> wrote in message
news:c3e0io$a15$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
news:c3du2o$4tn$2 digitaldaemon.com...
 The problem is there's a template in std which matches the template you
 defined in the global namespace. By bringing std's symbol table into the
 global namespace, then there's a conflict. This is not a bug in DMC++.
[snip] So, what to do?
Decide which version of the template you wish to use, and either delete the other one or turn off importing the namespace.
 P.S. GNU g++ 3.3.1, Microsoft C++ 13.00.9466, Borland C++ 5.5.1 have no
problem with that code. It's not the first time DMC++ is the only compiler that gets it right!
Mar 18 2004