forked from boostorg/conversion
add more tests and documentation example for polymorphic_pointer_downcast
This commit is contained in:
1 parent
6a224fa5e9
commit
582fc91adb
2 files changed
+131
-5
No files matched your search
@@ -134,6 +134,30 @@ void f( Fruit * fruit ) {
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<h3>polymorphic_pointer_downcast example</h3>
|
||||
|
||||
<blockquote>
|
||||
<pre>#include <boost/polymorphic_cast.hpp>
|
||||
|
||||
class Fruit { public: virtual ~Fruit(){} };
|
||||
class Banana : public Fruit {};
|
||||
|
||||
// use one of these:
|
||||
|
||||
typedef Fruit* FruitPtr;
|
||||
typedef std::shared_ptr<Fruit> FruitPtr;
|
||||
typedef boost::shared_ptr<Fruit> FruitPtr;
|
||||
typedef boost::intrusive_ptr<Fruit> FruitPtr;
|
||||
|
||||
void f(FruitPtr fruit)
|
||||
{
|
||||
// ... logic which leads us to believe it is a banana
|
||||
auto banana = boost::polymorphic_pointer_downcast<Banana>(fruit);
|
||||
...
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<h3>History</h3>
|
||||
|
||||
<p><code>polymorphic_cast</code> was suggested by Bjarne Stroustrup in "The C++
|
||||
|
||||
Reference in new issue
Block a user