locked
How to use < shared_ptr > RRS feed

  • Question

  • I have some code that uses a shared_ptr from the <memory> library.  My compiler, however, doesn't recognize shared_ptr.  I've checked the following items:
    • I have #include <memory> in my header file. 
    • I have also declared the std::tr1 namespace. 
    • I've open the memory file and there is no shared_ptr! 
    • My header file is dated 29/06/2006.  Perhaps it's an old version?
    Would anyone be able to suggest what could be wrong?
    I am using Visual Studio 2008, version 9.030729.1 SP and .NET Framework version 3.5 SP1.  I've also updated the software from the Microsoft website.
    Thanks very much in advance,
    Nikolai.
    Thursday, June 18, 2009 3:55 PM

Answers

  • Maybe you aren't fully qualifying the namespace?

    If it exists in the std::tr1 namespace as Brian Muth mentioned it might be hidden from you.

    Try specifying the namespace.

    tr1::shared_ptr then std::tr1::shared_ptr.
    Leo Violette - Software Engineer in Redmond Washington.
    Wednesday, June 24, 2009 10:05 AM

All replies

  • If you have VS 2008 SP1 installed, you'll have it. You are correct: it is in the std::tr1 namespace.
    Thursday, June 18, 2009 5:09 PM
  • The date is wrong,  memory.h is 29/06/2006, memory is 04/06/2008.  Are you looking at the correct one?  Start + Run, Explorer, Tools, Folder Options, View tab, turn off "Hide extensions for known file types".
    Hans Passant.
    Thursday, June 18, 2009 5:37 PM
  • Hmm, ok, it looks like I have an old memory file because mine is dated 22/02/2007!  How would I go about getting the new version, seeing as I've already fully updated my software from the Microsoft website???

    Thanks very much.
    Nikolai.
    Friday, June 19, 2009 8:42 AM
  • This could happen if you accidentally modified the file some time before you ran the SP1 update.  Rename the file and do a Repair.
    Hans Passant.
    Friday, June 19, 2009 9:37 AM
  • Thanks for the reply Hans.

    It still doesn't work.  I've even completely re-installed the program from the CD, and re-did the Microsoft update to re-install SP1, and it doesn't replace the old memory file...  It seems like the update site isn't recognizing that I have an older version of the file.  Is there a way of forcing the replacement by hand?  I work in France, so we use a french version of VS2008.  Could it be that???

    Thanks again.
    Nikolai.
    Friday, June 19, 2009 11:47 AM
  • Did you in fact rename the file first?  And the new one you got has the same date as the renamed one?

    Hans Passant.
    Friday, June 19, 2009 11:55 AM
  • Yes!
    Friday, June 19, 2009 1:30 PM
  • Any ideas??  Thanks.
    Monday, June 22, 2009 7:11 AM
  • Maybe you aren't fully qualifying the namespace?

    If it exists in the std::tr1 namespace as Brian Muth mentioned it might be hidden from you.

    Try specifying the namespace.

    tr1::shared_ptr then std::tr1::shared_ptr.
    Leo Violette - Software Engineer in Redmond Washington.
    Wednesday, June 24, 2009 10:05 AM