c++ multiple definitions of operator<<
问题 I am attempting to override the << operator for a class. The purpose is basically to implement a toString() like behavior for my class, so that sending it to cout will produce useful output. Using a dummy example, I have the code below. When I attempt to compile, I get the foollowing error: $ g++ main.cpp Rectangle.cpp /tmp/ccWs2n6V.o: In function `operator<<(std::basic_ostream<char, std::char_traits<char> >&, CRectangle const&)': Rectangle.cpp:(.text+0x0): multiple definition of `operator<<