|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71531 - sandbox/mutual_ptr/libs/smart_ptr/doc
From: phil_at_[hidden]
Date: 2011-04-26 21:46:44
Author: pbouchard
Date: 2011-04-26 21:46:43 EDT (Tue, 26 Apr 2011)
New Revision: 71531
URL: http://svn.boost.org/trac/boost/changeset/71531
Log:
* Added caveat to the tutorial
Text files modified:
sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
Modified: sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html
==============================================================================
--- sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html (original)
+++ sandbox/mutual_ptr/libs/smart_ptr/doc/tutorial.html 2011-04-26 21:46:43 EDT (Tue, 26 Apr 2011)
@@ -61,6 +61,8 @@
<dt>Basic</dt>
<dt>Advanced</dt>
+
+ <dt>Caveat</dt>
</dl>
<h2><a name="basic" id="basic"></a>Basic</h2>
@@ -96,6 +98,33 @@
c.push_back(new mutual<int>(11));
</pre>
+ <h2><a name="caveat" id="caveat"></a>Caveat</h2>
+
+ <p>Hierarchies with multiple inheritance without virtual tables will cause undefined behavior if a pointer to a derived class is assigned to a pointer of one
+ of its base class. For example:</p>
+
+ <pre>
+ struct M { int i; };
+ struct N { int i; };
+ struct O : N, M { int i; };
+
+ mutual_ptr<O> po = new mutual<O>;
+ mutual_ptr<N> pn = po; // incorrect
+ mutual_ptr<M> pm = po; // incorrect
+ </pre>
+
+ <p>A way to bypass any problem that might be created by the example above is to add virtual destructors to the classes:</p>
+
+ <pre>
+ struct M { int i; virtual ~M() {} };
+ struct N { int i; virtual ~N() {} };
+ struct O : N, M { int i; };
+
+ mutual_ptr<O> po = new mutual<O>;
+ mutual_ptr<N> pn = po; // correct
+ mutual_ptr<M> pm = po; // correct
+ </pre>
+
<hr>
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk