fungus wrote:
> Rolf Magnus wrote:
>> That should work. Your code is a bit short, so it's
>> hard to tell why it wouldn't.
>
> I'll have another play with it and see what happens...
>
I figured it out - it's all to do with namespaces.
Here's a "broken" piece of code:
#include <iostream>
#include <string>
namespace foo {
class A {
public:
void writeTo(std:

stream& os) const {
os << "A";
}
};
void operator<<(std:

stream& os, const class B&);
void test();
}
template<typename T, typename S>
S& operator<<(S& d, const T& t)
{
t.writeTo(d);
return d;
}
void foo::test()
{
A a;
std::cout << a << '\n';
}
int main(int argc,char **argv)
{
foo::test();
}
The operator<< in namespace foo is hiding the template
operator<< (which is in the global namespace).
--
<\___/>
/ O O \
\_____/ FTB. For email, remove my socks.
We’re judging how a candidate will handle a nuclear
crisis by how well his staff creates campaign ads.
It’s a completely nonsensical process.