Hi All,
I just want to know whether use of shared_ptr is justified in below code here or do i need to use unique_ptr instead of shared_ptr?
#include <iostream>
#include <memory>
using namespace std;
class a
{
int a1 ,b;
public:
a(int x=0,int y=0):a1(x),b(y){}
void fun1() {cout<<a1;cout<<b;}
};
class b
{
private:
std::shared_ptr <a> p;
public:
b (int x=0, int y=0):p( new a (x,y)){}
b ( const b &obj):p(new a(*obj.p)){}
void fun2(){p->fun1();}
};
int main()
{
b obj1(10,20);
b obj2(obj1);
obj2.fun2();
return 1;
}