Re: overloaded operator lookup wierdness
catphive <catphive@gmail.com> writes:
On Aug 28, 3:04 pm, Thomas Maeder <mae...@glue.ch> wrote:
catphive <catph...@gmail.com> writes:
I'm having something weird go on with overloaded operator lookup.
I have something like
namespace n {
ostream& operator <<(ostream& os, const SomeType& v);
So here SomeType is the name of a type. What type? What namespace does
it belong to?
In my case it happened to be std::vector that had been moved into
the global namespace via using std::vector.
A using declaration doesn't move anything. It creates an alias for a
name in a different namespace.
I'm not *trying* to depend on argument dependant lo lookup here. I'm
*trying* to call a function which happens to be an overloaded
operator from within an anonymous namespace nested in namespace n.
namespace n {
ostream& operator <<(ostream& os, const vector<int>& v);
}
namespace n {
namespace {
void fun(const vector<int>& v) {
cout << v;
}
}
}
I had asked you to post the program that causes the compiler to
produce the error message you are asking about. You still haven't. For
the above program, the compiler will complain about ostream being
undeclared and many other things. How can you assume that other people
spend time on your problem if you are not willing to spend time to
save theirs?
FWIW, this program:
#include <iostream>
#include <ostream>
#include <vector>
namespace n {
std::ostream& operator <<(std::ostream& os, const std::vector<int>& v)
{
return os;
}
}
namespace n {
namespace {
void fun(const std::vector<int>& v)
{
std::cout << v;
}
}
}
int main()
{
std::vector<int> v;
n::fun(v);
}
compiles and links on gcc 4.1.2 and compiles on Comeau online, as I
think it should.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]