Topic: namespace and operator<<
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sun, 11 Dec 1994 03:20:04 GMT Raw View
In article <3c7g47$bhp@hpsystem1.informatik.tu-muenchen.de> schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann) writes:
>
> namespace A {
>[...]
> ostream& operator<<(ostream& os, const X& x) {
> return os << x.x;
> }
> }
>
>How do I just get this one operator from the namespace?
>A using-declartion wants an identifier. Is "operator<<" an
>identifier (in this case or generally)? Can I write:
>
> using A::operator<<;
Yes. But:
A::X x;
cout << x; // woops! Doen't work.
cout.A::operator<<(x); // works but is unacceptably ugly
Having to write that is not on. A solution is being sought.
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189
Author: kuhlins@hawk.wifo.uni-mannheim.de (Stefan Kuhlins)
Date: 05 Dec 1994 13:02:27 GMT Raw View
How to define an output-operator for a class in a namespace?
(I tested the following example with Metaware High C++ 3.2 for OS/2.)
Please answer per email, too. Thanks.
// headerfile n.h
#include <iostream.h>
namespace A {
class X {
friend ostream& operator<<(ostream&, const X&);
public:
X(int);
private:
int x;
};
}
// file n.cpp
// #include "n.h"
namespace A {
X::X(int i) : x(i) {}
ostream& operator<<(ostream& os, const X& x) {
return os << x.x;
}
}
// file test.cpp
// #include "n.h"
int main() {
A::X x(10);
cout << x; // error
A::operator<<(cout, x); // ok, but this isn't what I want...
return 0;
}
Author: raghav@deneb.cs.binghamton.edu (_)
Date: 05 Dec 1994 18:19:52 GMT Raw View
What is namespace?
thanx
amritansh
Author: kuhlins@hawk.wifo.uni-mannheim.de (Stefan Kuhlins)
Date: 06 Dec 1994 09:27:33 GMT Raw View
In article <RAGHAV.94Dec5131953@deneb.cs.binghamton.edu> raghav@deneb.cs.binghamton.edu (_) writes:
What is namespace?
Have a look at the following document:
ftp world.std.com
cd AW/stroustrup2e
get iso.ps
- Stefan
Author: mendell@opus.torolab.ibm.com (Mark Mendell)
Date: 6 Dec 1994 18:19:33 GMT Raw View
You need to put a 'using namespace A;' statement into your file. This 'opens'
the namespace and allows reference to the symbols within it.
--
Mark Mendell
C Set ++ for AIX Development
IBM Toronto Lab
mendell@vnet.ibm.com
Author: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Date: 8 Dec 1994 17:35:03 GMT Raw View
In article <3c29vl$1rkm@tornews.torolab.ibm.com>, mendell@opus.torolab.ibm.com (Mark Mendell) writes:
|> You need to put a 'using namespace A;' statement into your file. This 'opens'
|> the namespace and allows reference to the symbols within it.
|> --
namespace A {
[...]
ostream& operator<<(ostream& os, const X& x) {
return os << x.x;
}
}
How do I just get this one operator from the namespace?
A using-declartion wants an identifier. Is "operator<<" an
identifier (in this case or generally)? Can I write:
using A::operator<<;
Ulf Schuenemann
--------------------------------------------------------------------
Ulf Sch nemann
Institut f r Informatik, Technische Universit t M nchen.
email: schuenem@informatik.tu-muenchen.de