Original Post
Hi there. I have a file a.h which declares and defines the ostream<<X operator for a class X. b.h includes a.h and main.cpp includes b.h In main.cpp this is fine: X test(init); cout << X; In b.h this is not fine: X test(init); cout << X; (Both examples are themselves in global scope.) The full error is two screenfulls of stuff which starts with no match for 'operator<<' in 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(+o)) and continues in a similarly unreadable way. As far as I can tell, it's as if ostream<<X was never defined. Since main.cpp is only aware of the operator because it includes b.h which includes a.h where it is defined, surely b.h should see it too? I had a similar looking pile of errors when I tried to seperate the declerations into .h files and definitions into .cpp files, according to the stylistic advice in my book (I'm coming back to c++ after a few years' hiatus). I couldn't suss it out then and gave up, I think it's much the same problem. Any insights? Thanks a lot.