Click here to Skip to main content
12,632,072 members (26,215 online)
Click here to Skip to main content

Stats

114.6K views
2.8K downloads
109 bookmarked
Posted

C++11 Smart Pointers

, 26 Sep 2013 CPOL
Various Smart Pointers in C++11
SharedPtr
SharedPtr
SharedPtr.opensdf
SharedPtr.vcxproj.filters
UniquePtr
UniquePtr
UniquePtr.vcxproj.filters
WeakPtr
WeakPtr
WeakPtr.vcxproj.filters
#include <memory>
#include <iostream>
using namespace std;

class Test
{
public:
	Test(int a = 0) : m_a(a) { }
	~Test( )
	{
		cout<<"Test object is destroyed whose value is = "<<m_a<<endl;
	}
public:
		int m_a;
};
//*********************************************************************************************************
class B;
class A
{
public:
		A()
		{
		}
		~A( )
		{
			cout<<"DestructorA is called"<<endl;
		}
		shared_ptr<B>  m_spToB;
};
//*********************************************************************************************************
class B
{
public:
		B()
		{
		}
		~B()
		{
			cout<<"DestructorB is called"<<endl;
		}
		shared_ptr<A>  m_spToA;
};
//*********************************************************************************************************
class D;
class C
{
public:
		C()
		{
		}
		~C()
		{
			cout<<"DestructorC is called"<<endl;
		}
		weak_ptr<D>  m_wpToD;
};
//*********************************************************************************************************
class D
{
public:
		D()
		{
		}
		~D()
		{
			cout<<"DestructorD is called"<<endl;
		}
		weak_ptr<C>  m_wpToC;
};
//*********************************************************************************************************

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Babu_Abdulsalam
Software Developer (Senior)
India India
I'm working as Senior software Engineer since 7 years and interested in MFC and COM programming.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 26 Sep 2013
Article Copyright 2013 by Babu_Abdulsalam
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid