Topic: Is using X::operator<< valid?


Author: eric_backus@alum.mit.edu ("Eric Backus")
Date: Wed, 31 Mar 2004 05:24:52 +0000 (UTC)
Raw View
""Roger Orr"" <rogero@howzatt.demon.co.uk> wrote in message
news:c4a85m$m6d$1$8302bc10@news.demon.co.uk...
> ""Eric Backus"" <eric_backus@alum.mit.edu> wrote in message
> news:1080174204.481226@cswreg.cos.agilent.com...
> > The following code attempts to use a "using" directive on an operator.
I
> > think this should be valid C++ code, and it is accepted by MS C++ 7.1,
but
> > gcc gives me an error on the "using" line.  Is this valid code?
>
> Yes, using is valid for operators.
>
> A using declaration takes, among other things, an unqualified-id. (A.6
> declarations)
> This explicitly includes an operator-function-id such as operator<<
>
> Which version of gcc ?
>
> Roger Orr

It happens for sure on "gcc version 3.2 20020927 (prerelease)", as supplied
by cygwin 1.3.20, running under Windows XP SP1.

I think I also saw it on gcc 3.3.1 running on SuSE linux 9.0.

--
Eric Backus

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: eric_backus@alum.mit.edu ("Eric Backus")
Date: Thu, 25 Mar 2004 01:20:44 +0000 (UTC)
Raw View
The following code attempts to use a "using" directive on an operator.  I
think this should be valid C++ code, and it is accepted by MS C++ 7.1, but
gcc gives me an error on the "using" line.  Is this valid code?


#include <iostream>
#include <list>

namespace X
{
 // Declare operator<< for list<int> type, inside namespace X
 std::ostream&
 operator<<(std::ostream& os, const std::list<int>& l)
 {
  return os;
 }
}

int
main()
{
 std::list<int> l;

 using X::operator<<; // Is this valid?

 std::cout << l; // Should this use X::operator<< ?

 return 0;
}



--
Eric Backus
R&D Design Engineer
Agilent Technologies, Inc.
425-356-6010 Tel

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rogero@howzatt.demon.co.uk ("Roger Orr")
Date: Mon, 29 Mar 2004 23:34:25 +0000 (UTC)
Raw View
(to mods: resent since previous posting 48hrs ago didn't get a reply from
the robomoderator.  Please discard if previous message reappears)

""Eric Backus"" <eric_backus@alum.mit.edu> wrote in message
news:1080174204.481226@cswreg.cos.agilent.com...
> The following code attempts to use a "using" directive on an operator.  I
> think this should be valid C++ code, and it is accepted by MS C++ 7.1, but
> gcc gives me an error on the "using" line.  Is this valid code?
>

Yes, using is valid for operators.

A using declaration takes, among other things, an unqualified-id. (A.6
declarations)
This explicitly includes an operator-function-id such as operator<<

Which version of gcc ?

Roger Orr
--
MVP in C++ at www.brainbench.com


---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]