rel_ops and namespace

P

PengYu.UT

#include <iostream>
Hi,

I don't understand why "using" in namespace A is not working. I would
assume it is more reasonable to use Koenig lookup (http://
en.wikipedia.org/wiki/Argument_dependent_name_lookup).

For B is defined in namespace A, shall it be OK to using "rel_ops" in
A instead of the global namespace?

Thanks,
Peng

#include <utility>

namespace A {

// using namespace std::rel_ops; // not working
class B {
public:
B(int b):_b(b) { }
bool operator==(const B& b) const {
return _b == b._b;
}
private:
int _b;
};
}

using namespace std::rel_ops; // works

int main() {
A::B b1(10);
A::B b2(10);
std::cout << (b1 == b2) << std::endl;
std::cout << (b1 != b2) << std::endl;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top