Topic: Is "using namespace x" legal in a class declaration?
Author: msherman@magma.ca (Marc Sherman)
Date: 1998/04/26 Raw View
Is the following code legal, and does it do what I want (associate
the std::rel_ops templates with class MyClass)? If not, is there any way
to make this association without wrapping MyClass in its own namespace?
How was std::rel_ops intended to be used?
class MyClass
{
public:
friend bool operator<(const MyClass&);
friend bool operator==(const MyClass&);
using namespace std::rel_ops;
};
Thanks...
- Marc
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: loewis@informatik.hu-berlin.de (Martin v. Loewis)
Date: 1998/04/27 Raw View
msherman@magma.ca (Marc Sherman) writes:
> Is the following code legal, and does it do what I want (associate
> the std::rel_ops templates with class MyClass)? If not, is there any way
> to make this association without wrapping MyClass in its own namespace?
> How was std::rel_ops intended to be used?
>
> class MyClass
> {
> public:
> friend bool operator<(const MyClass&);
> friend bool operator==(const MyClass&);
> using namespace std::rel_ops;
> };
This is not legal. [namespace.udir]/1 specifies:
A using directive shall not appear in class scope, ...
In order to use them with your class, I believe callers of those
templates should put using directives into the blocks where they
need the operators.
Regards,
Martin
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]