title: Boost example code inheriting from std::exception doesn't link
body: <p>This article from <a href="http://www.boost.org/community/error_handling.html" rel="nofollow">boost: Error and Exception Handling</a> puts forth the following program code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  struct my_exc1 : std::exception {
    char const* what() const throw();
  };
  struct my_exc2 : std::exception {
    char const* what() const throw();
  };
  struct your_exc3 : my_exc1, my_exc2 {};
  
  int main() {
    try {
      throw your_exc3();
    } catch(std::exception const&amp; e) {}
    catch(...) {
      std::cout &lt;&lt; "whoops!" &lt;&lt; std::endl;
    }
  }
  </code></pre>
  
  <p>When compiling with g++ (GCC) 5.2.0, I get the following</p>
  
  <pre><code>&gt; g++ -std=c++11 custom_exception.cpp
  /tmp/ccmbzPOk.o: In function `my_exc1::my_exc1()':
  custom_exception.cpp:(.text._ZN7my_exc1C2Ev[_ZN7my_exc1C5Ev]+0x19): undefined reference to `vtable for my_exc1'
  /tmp/ccmbzPOk.o: In function `my_exc1::~my_exc1()':
  custom_exception.cpp:(.text._ZN7my_exc1D2Ev[_ZN7my_exc1D5Ev]+0xd): undefined reference to `vtable for my_exc1'
  /tmp/ccmbzPOk.o: In function `my_exc2::my_exc2()':
  custom_exception.cpp:(.text._ZN7my_exc2C2Ev[_ZN7my_exc2C5Ev]+0x19): undefined reference to `vtable for my_exc2'
  /tmp/ccmbzPOk.o: In function `my_exc2::~my_exc2()':
  custom_exception.cpp:(.text._ZN7my_exc2D2Ev[_ZN7my_exc2D5Ev]+0xd): undefined reference to `vtable for my_exc2'
  /tmp/ccmbzPOk.o:(.rodata._ZTV9your_exc3[_ZTV9your_exc3]+0x20): undefined reference to `my_exc1::what() const'
  /tmp/ccmbzPOk.o:(.rodata._ZTV9your_exc3[_ZTV9your_exc3]+0x48): undefined reference to `my_exc2::what() const'
  /tmp/ccmbzPOk.o:(.rodata._ZTI9your_exc3[_ZTI9your_exc3]+0x18): undefined reference to `typeinfo for my_exc1'
  /tmp/ccmbzPOk.o:(.rodata._ZTI9your_exc3[_ZTI9your_exc3]+0x28): undefined reference to `typeinfo for my_exc2'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I have seen the identical technique used elsewhere, suggesting to me that this should compile (and link) silently. (As an example, I cite Anthony Williams <em>C++ Concurrency in Action</em> p. 45 where he inherits from <code>std::exception</code> to make <code>empty_stack</code> for the thread-safe stack example.)</p>
  
  <p>I have tried to <code>#include &lt;exception&gt;</code> and despite the fact that this isn't a C++ library problem, I even tried the <code>-lstdc++</code> flag on the advice of people with similar problems---out of desperation.</p>
  
  <p>I understand that in <code>std::exception</code>, <code>what()</code> is virtual, meaning I should define it---so I'm not sure why it should compile in the first place, but I'm frustrated that it apparently does for other people.</p>
  
  <p>My questions are two: (1) What is the problem, and why does it work for others? (2, conditionally) New to C++, I should also ask what is a good way to implement <code>what()</code> (assuming I will have to) in the most minimal way, since I don't actually want to pass a string with my exception. I don't need to inherit from deeper in the hierarchy, such as <code>std::runtime_error</code>.</p>