<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Object Oriented on The Lone C++ Coder's Blog</title><link>https://www.lonecpluspluscoder.com/tags/object-oriented/</link><description>Recent content in Object Oriented on The Lone C++ Coder's Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Wed, 19 Nov 2014 22:24:02 +0000</lastBuildDate><atom:link href="https://www.lonecpluspluscoder.com/tags/object-oriented/index.xml" rel="self" type="application/rss+xml"/><item><title>Polymorphism and boost::shared_ptr</title><link>https://www.lonecpluspluscoder.com/2014/11/19/polymorphism-and-boost-shared_ptr/</link><pubDate>Wed, 19 Nov 2014 22:24:02 +0000</pubDate><author>Timo Geusch</author><guid>https://www.lonecpluspluscoder.com/2014/11/19/polymorphism-and-boost-shared_ptr/</guid><description>&lt;p&gt;&lt;em&gt;Reposted from my old blog. Here&amp;rsquo;s the news from 2009&amp;hellip;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m currently in the final stages of converting a library from raw pointers to &lt;a href="http://www.boost.org/doc/libs/1_57_0/libs/smart_ptr/shared_ptr.htm"&gt;boost::shared_ptr&lt;/a&gt;. I&amp;rsquo;m mainly doing this to ensure the correct pointer/pointee ownership rather than the outright prevention of memory leaks, but the latter is a nice side effect of the former.&lt;/p&gt;
&lt;p&gt;One problem I ran into was that the library I&amp;rsquo;m updating and its clients make rather heavy use of polymorphism. Of course in 99% of the code that was fine as the objects were accessed through pointers to base classes, but the last 1% was causing problems because that part of the code contained lots of &lt;code&gt;dynamic_cast&lt;/code&gt; statements. These classes unfortunately need to know the exact type they were dealing with so there was no easy way around the use of these idioms. It probably isn&amp;rsquo;t news to most of the people reading this blog that dynamic_cast and boost::shared_ptr don&amp;rsquo;t play that nicely.&lt;/p&gt;</description></item></channel></rss>