Language Subtlety or Compiler bug?
From: Ned Harding (nharding_at_extendthereach.com)
Date: 08/31/04
- Next message: Victor Bazarov: "Re: Linked list"
- Previous message: Matthew Hall: "Re: using memcpy to copy classes"
- Next in thread: Howard: "Re: Language Subtlety or Compiler bug?"
- Reply: Howard: "Re: Language Subtlety or Compiler bug?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Aug 2004 10:25:03 -0700
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;
}
- Next message: Victor Bazarov: "Re: Linked list"
- Previous message: Matthew Hall: "Re: using memcpy to copy classes"
- Next in thread: Howard: "Re: Language Subtlety or Compiler bug?"
- Reply: Howard: "Re: Language Subtlety or Compiler bug?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|