A while back I posted some code along with an error message I got when I
tried to compile it. I thought at one point I had solved all the problems.
But then I tried it again, and if failed. The code I posted here didn't
have namespaces in it. I had originally tried to compile the same code
with namespaces. The one subtlety I missed was that overloaded operator
definitions are namespace local. If I declare this in my header file:
//BaseNode.hh
namespace sth{
ostream& operator<<(ostream& out, const BaseNode& bn);
}
I have to qualify the operator<<(...); like this:
//BaseNode.cc
ostream& sth::operator<<(ostream& out, const BaseNode& bn)
{
return bn.print(out);
}
Note the sth:: before the operator<<(..) I had not been doing that. That
caused the compile to fail. I then put the definition back in the header
file, and that violated the ODR. Put all the code in one file, and it all
worked fine.
This is the original message I'm referring to:
news://Message-ID: <_c********************@speakeasy.net>
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org