title: Wrapping the pure virtual function using Boost::Python
body: <p>I am now learning exposing c++ class to Python using <code>Boost::Python</code>, and I wrote the following code.</p>
  
  <p>Compiling the code is all right. But when I import the code from Python side, it shows the following errors:</p>
  
  <p>Traceback (most recent call last):
    File "test4.py", line 1, in </p>
  
  <pre><code>import shape;
  </code></pre>
  
  <p>ImportError: /home/ruofan/Boost/Class/shape.so: undefined symbol: _ZTI7Polygon</p>
  
  <p>How can I solve the problem?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/python.hpp&gt;
  
  using namespace boost::python;
  using namespace std;
  
  class Polygon {
    protected:
      int width, height;
    public:
      Polygon (int a, int b) : width(a), height(b) {}
      virtual int area (void) =0;
      void printarea()
        { cout &lt;&lt; this-&gt;area() &lt;&lt; '\n'; }
      virtual ~Polygon(); 
  };
  
  class Rectangle: public Polygon {
    public:
      Rectangle(int a,int b) : Polygon(a,b) {}
      int area()
        { return width*height; }
      virtual ~Rectangle();
  };
  
  class Triangle: public Polygon {
    public:
      Triangle(int a,int b) : Polygon(a,b) {}
      int area()
        { return width*height/2; }
      virtual ~Triangle();
  };
  
  struct BaseWrap : Polygon, wrapper&lt;Polygon&gt; {
    BaseWrap() : Polygon(0,0){}
    int area(){
          return this-&gt;get_override("area")();
    }
  };
  
  
  BOOST_PYTHON_MODULE(shape){
    class_&lt;BaseWrap, boost::noncopyable&gt;("Polygon")
      .def("area", pure_virtual(&amp;Polygon::area));
  }
  </code></pre>