In VC7.1 the following code outputs:
00000000
Success!
It would seem that the Y::operator<< is hiding the global operator<<
when it is outputting an object from another namespace but not when it
is outputting an object in the global namespace.
I can't help but think one of these 2 behaviors is a bug in VC7.1, but
which one?
Thanks,
Ned.
=============== =============== ===========
#include <iostream>
namespace X
{
class Abc1
{
};
}
std::ostream& operator<< (std::ostream& strm, const X::Abc1 *node)
{
return strm << "Success!";
}
X::Abc1 * GetDoc() { return NULL; }
class Abc2
{
};
Abc2 * GetDoc2() { return NULL; }
std::ostream& operator<< (std::ostream& strm, const Abc2 *node)
{
return strm << "Success!";
}
namespace Y
{
std::ostream & operator<<(std: :ostream& a, const char& b)
{
return a << "This should not run";
}
void DoTest()
{
std::cout << GetDoc() << "\n";
std::cout << GetDoc2() << "\n";
}
}
int main(int argc, char* argv[])
{
Y::DoTest();
return 0;
}
00000000
Success!
It would seem that the Y::operator<< is hiding the global operator<<
when it is outputting an object from another namespace but not when it
is outputting an object in the global namespace.
I can't help but think one of these 2 behaviors is a bug in VC7.1, but
which one?
Thanks,
Ned.
=============== =============== ===========
#include <iostream>
namespace X
{
class Abc1
{
};
}
std::ostream& operator<< (std::ostream& strm, const X::Abc1 *node)
{
return strm << "Success!";
}
X::Abc1 * GetDoc() { return NULL; }
class Abc2
{
};
Abc2 * GetDoc2() { return NULL; }
std::ostream& operator<< (std::ostream& strm, const Abc2 *node)
{
return strm << "Success!";
}
namespace Y
{
std::ostream & operator<<(std: :ostream& a, const char& b)
{
return a << "This should not run";
}
void DoTest()
{
std::cout << GetDoc() << "\n";
std::cout << GetDoc2() << "\n";
}
}
int main(int argc, char* argv[])
{
Y::DoTest();
return 0;
}
Comment