Thread: Smart Pointer question

  1. #1
    Registered User
    Join Date
    May 2010

    Smart Pointer question

    How are smart pointers used when the precise type of objects needed are unknown
    How would a shared_ptr or a unique_ptr resolve this? What about the class weak_ptr which is a weak reference to a shared_ptr?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    As in when you have a polymorphic base class, but the exact derived class types will only be known at runtime? The solution is to use a smart pointer of the base class type then.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. COM smart pointer / C++ smart pointer
    By KIBO in forum Windows Programming
    Replies: 1
    Last Post: 02-23-2011, 05:14 AM
  2. smart pointer+allocator?
    By idleman in forum C++ Programming
    Replies: 3
    Last Post: 11-17-2009, 11:51 AM
  3. Which smart pointer to use?
    By leeor_net in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2009, 04:29 AM
  4. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  5. pointer and smart pointer address
    By l2u in forum C++ Programming
    Replies: 14
    Last Post: 12-26-2006, 05:00 PM