In the below code, the output is turning out to be blank instead of constructor and destructor printouts. Without move operation, the code is working well. I am somehow messing up the move operation, please go through and give your inputs to guide further.
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
using namespace std;
template <class T>
class smart{
public:
smart():pt{nullptr}{
}
smart(T *ptr):pt{ptr}{
}
T *pt;
smart(const smart& ob)=delete;
smart operator=(const smart& ob)=delete;
smart (smart&& dyingob){
this->pt=dyingob.pt;
dyingob.pt=nullptr;
}
void operator=(smart&& dyingob){
pt=dyingob.pt;
dyingob.pt=nullptr;
}
T* operator ->(){return this->pt;};
~smart(){
if(pt!=nullptr)
delete pt;
}
};
class A{
public:
A(int n){
data=n;
cout<<"\nconstructed";
}
~A(){
cout<<"\ndestructed";
}
int data;
};
int main()
{
smart<A> ob(new A(5));
smart<A> ob1;
ob1=(std::move(ob));
cout<<ob->data;
return 1;
}