<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1><pre><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>I am currently running Boost Python on a Debian system, and I am running into an error with smart pointers. I have no problems with regular C++ pointers. <o:p></o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>There were issues with installing Boost Python 1.35, so we rolled it back to one that worked on the system (1.33). So this may be an issue with the version or the OS, I am not sure. <o:p></o:p></span></pre>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>After attempting much more complicated stuff that is more
related to what I am attempting to do, I am now following the simple example
that I have found online at <a
href="http://wiki.python.org/moin/boost.python/PointersAndSmartPointers">http://wiki.python.org/moin/boost.python/PointersAndSmartPointers</a>:<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>#include
<boost/shared_ptr.h> <o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>using
namespace boost;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>struct
A {<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
shared_ptr<A> create () { return shared_ptr<A>(new A); }<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
std::string hello () { return "Just nod if you can hear
me!"; }<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>};<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>BOOST_PYTHON_MODULE(shared_ptr)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>{<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
class_<A>("A",init<>())<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
.def("create",&A::create,return_value_policy<return_by_value>())<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
.staticmethod("create")<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
.def("hello",&A::hello)<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
class_< shared_ptr<A> >("A_ptr", init<const
shared_ptr<A>& >())<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
.def("__pos__",&boost::shared_ptr<A>::get,return_internal_reference<>())<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>
;<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>}<o:p></o:p></span></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Running the following python commands:<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<pre>from shared_ptr import *<o:p></o:p></pre><pre>an_A = A_ptr.create()<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>I keep getting the same error from the last line.<o:p></o:p></span></pre><pre><o:p> </o:p></pre><pre>Traceback (most recent call last):<o:p></o:p></pre><pre> File "<stdin>", line 1, in ?<o:p></o:p></pre><pre>AttributeError: type object 'A_ptr' has no attribute 'create'<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>This makes sense to me because A_ptr doesn’t have a create attribute(calling A.create() does not work either), but this is the way the tutorial says to do it. <o:p></o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>Any help here would be appreciated.<o:p></o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>Thanks,<o:p></o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>Matt <o:p></o:p></span></pre><pre><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></pre><pre><o:p> </o:p></pre>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>