4 Replies - 648 Views - Last Post: 10 October 2011 - 10:04 AM Rate Topic: -----

#1 Kain6622  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 255
  • Joined: 18-March 10

Question regarding tr1 smart pointers

Posted 10 October 2011 - 08:44 AM

Hi, i'm trying to looking into using smart pointers for the new c++ standard for my applications but I'm unable to find any good sources of information about advanced use of them i.e. having two classes that need to share the same data member but the member is declared within one already but is required by the other but both classes are required to be seperate (no inheritance)? does anyone know where I might be able to find this sort of information or know roughly how it would be done? I've been searching google but can only find very basic and badly documented information on use of tr1.
thanks
regards
Dave

Is This A Good Question/Topic? 0
  • +

Replies To: Question regarding tr1 smart pointers

#2 eypros  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 08-October 11

Re: Question regarding tr1 smart pointers

Posted 10 October 2011 - 09:02 AM

Hello,

I think that most of the implemented issues in TR1 is form boost library so you can check:

http://www.boost.org/

for information about smart pointers
Was This Post Helpful? 1
  • +
  • -

#3 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Question regarding tr1 smart pointers

Posted 10 October 2011 - 09:02 AM

Under Boost, which has been providing the smart pointer implementations all this time. Most documentation should refer to the Boost smart pointers.

You shouldn't have to look under tr1 for a smart pointer implementation. It's there in C++11 standard now.
Was This Post Helpful? 1
  • +
  • -

#4 Kain6622  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 255
  • Joined: 18-March 10

Re: Question regarding tr1 smart pointers

Posted 10 October 2011 - 09:17 AM

Thanks for the replies, I've already looked on boost but didn't make much sense of it but i'll read it over some more times and try some of the examples. Oler1s i'm still using VS2008 which doesn't have the C++11 standard yet ( well the one i have ) but thank you for updating me I didn't know that.

thanks again for the help.
Was This Post Helpful? 0
  • +
  • -

#5 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 449
  • View blog
  • Posts: 849
  • Joined: 17-March 11

Re: Question regarding tr1 smart pointers

Posted 10 October 2011 - 10:04 AM

What you are looking for is called std::shared pointer in c++11

#include <iostream>
#include <memory>

int main() {
    {
        std::shared_ptr<int> a(new int(5));
        std::shared_ptr<int> b = a;
        std::cout << *a << " " << *b << std::endl;
    }
    //memory is released now.
}



The end result is very similar to automatic (gc) memory management like in java, when the last shared pointer, pointing to a resource is destroyed, the memory is released, but you can make infinite copies of the shared_ptr.

This post has been edited by Karel-Lodewijk: 10 October 2011 - 10:05 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1