I have a C++ class that is declared and implemented in a header file. I chose this because one cannot easily move between Debug and Release builds due to _GLIBCXX_DEBUG and precompiled libraries. For example, if I define _GLIBCXX_DEBUG, Boost will crash due to ABI changes in the source files.
The header only implementation has created a problem with duplicate symbols. For example, in the class below operator== and non-member swap will produce multiply defined symbols.
// Foo.hpp
namespace Bar
{
  template
  class Foo
  {
    ...
  };
  bool operator==(const Foo& a, const Foo& b) {
    ..
  }
}
namespace std
{
  template <>
  void swap(Bar::Foo& a, Bar::Foo& b)
  {
    a.swap(b);
  }
}
When declaration and implementation were split, the files (Foo.hpp and Foo.cpp) compiled and linked OK.
What is the trick to get this to compile and link properly?
 
     
    