...
Code Block | ||
---|---|---|
| ||
class Handle { public: Handle(); ~Handle() {} // correct. // ... private: std::tr1::shared_ptr<Body>ptr<Body> impl_; }; |
Note that we used a shared_ptr
to refer to the Body
. Other common smart pointers, including std::auto_ptr
, will still produce undefined behavior.
...
Code Block | ||
---|---|---|
| ||
class B { // ... }; B *getMeSomeSortOfB(); // ... class D; // incomplete declaration // ... B *bp = getMeSomeSortOfB(); D *dp = (D *)bp; // old-stlye cast: legal, but inadvisable dp = reinterpret_cast<Dcast<D *>>(bp); // new-style cast: legal, but inadvisable |
...
Wiki Markup |
---|
\[[Dewhurst 03|AA. C++ References#Dewhurst 04]\] Gotcha 39: Casting Incomplete Types |
...
EXP35-C. Ensure that the right hand operand of a shift operation is within range 03. Expressions (EXP) 04. Integers (INT)