www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - STLport 4.0 I/O streams

↑ ↓ ← Christof Meerwald <cmeerw web.de> writes:
I have extracted 2 test-cases from the STLport 4.0 I/O streams library where
DM doesn't behave as expected:

  template<class T>
  struct A
  { };

  template<class T, class T2>
  struct S
  { };

  template<class T, class T2>
  int operator<<(S<T, T2> &s, T x)
  {
    return 1;
  }

  template<class T2>
  int operator<<(S<char, T2> &s, char x)
  {
    return 0;
  }

  int main(int argc, char *argv[])
  {
    S<char, A<char> > s;

    return s << 'a';
    // Error: ambiguous reference to symbol
    // Had: operator <<(S<>&,T)
    // and: operator <<(S<>&,char )
  }


...and the second test-case:

  template<class T>
  struct A
  { };

  template<class T, class T2>
  struct S
  {
    int operator<<(int x)
    {
      return 0;
    }
  };

  template<class T2>
  int operator<<(S<char, T2> &s, signed char x)
  {
    return 1;
  }

  template<class T2>
  int operator<<(S<char, T2> &s, unsigned char x)
  {
    return 1;
  }


  int main(int argc, char *argv[])
  {
    S<char, A<char> > s;
    int x = 0;

    return s << x;
    // Error: ambiguous reference to symbol
    // Had: operator <<(S<>&,signed char )
    // and: S<char ,A<char > >::operator <<(int )
  }


I would expect both programs to return 0 (that's what happens when compiling
them with GNU C++ 3.0.1).


bye, Christof

-- 
http://cmeerw.cjb.net                          Jabber: cmeerw jabber.at
mailto cmeerw at web.de                   ICQ: 93773535, Yahoo!: cmeerw

...and what have you contributed to the Net?
Oct 14 2001
↑ ↓ → Damian <damiandixon netscape.net> writes:
I found that the problem was due to a forward declaration
and then an implementation being visible at the same time.

     // Error: ambiguous reference to symbol
     // Had: operator <<(S<>&,signed char )
     // and: S<char ,A<char > >::operator <<(int )

I email the c.announce newsgroup with a similar problem on the 3/10/2001. The beta compiler appeared to fix the problem with STLport4.0. Regards, Damian Christof Meerwald wrote:
 I have extracted 2 test-cases from the STLport 4.0 I/O streams library where
 DM doesn't behave as expected:
 
   template<class T>
   struct A
   { };
 
   template<class T, class T2>
   struct S
   { };
 
   template<class T, class T2>
   int operator<<(S<T, T2> &s, T x)
   {
     return 1;
   }
 
   template<class T2>
   int operator<<(S<char, T2> &s, char x)
   {
     return 0;
   }
 
   int main(int argc, char *argv[])
   {
     S<char, A<char> > s;
 
     return s << 'a';
     // Error: ambiguous reference to symbol
     // Had: operator <<(S<>&,T)
     // and: operator <<(S<>&,char )
   }
 
 
 ...and the second test-case:
 
   template<class T>
   struct A
   { };
 
   template<class T, class T2>
   struct S
   {
     int operator<<(int x)
     {
       return 0;
     }
   };
 
   template<class T2>
   int operator<<(S<char, T2> &s, signed char x)
   {
     return 1;
   }
 
   template<class T2>
   int operator<<(S<char, T2> &s, unsigned char x)
   {
     return 1;
   }
 
 
   int main(int argc, char *argv[])
   {
     S<char, A<char> > s;
     int x = 0;
 
     return s << x;
     // Error: ambiguous reference to symbol
     // Had: operator <<(S<>&,signed char )
     // and: S<char ,A<char > >::operator <<(int )
   }
 
 
 I would expect both programs to return 0 (that's what happens when compiling
 them with GNU C++ 3.0.1).
 
 
 bye, Christof
 
 

Oct 17 2001