Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 0.24 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Get shared_ptr by reference with dynamic_pointer_cast
  2. struct A
  3. {
  4. };
  5.  
  6. struct B : public A
  7. {
  8. };
  9.  
  10. int main()
  11. {
  12.   shared_ptr<A> b = make_shared<B>();
  13.   auto &a = dynamic_pointer_cast<A>(b);
  14.   //auto a = dynamic_pointer_cast<A>(b);
  15.  
  16.   return 0;
  17. }