problem
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class tt
{
public:
int *data;
tt(/* args */);
~tt();
tt& operator=(const tt& rhs){
if(this==&rhs)
return *this;
delete data; //for obj to obj like (jon = kevin) line number 46
data=new int;
*data=*rhs.data;
return *this;
}
tt& operator=(tt&& rhs){
if(this==&rhs)
return *this;
delete data; //for R value to pointer pointing to like line nuber 45 and 47
data=new int;
*data=*rhs.data;
rhs.data=nullptr;
return *this;
}
};
tt::tt(/* args */)
{
}
tt::~tt()
{
}
int main(){int ho=8;
tt jon,kevin;
jon.data=&ho;
*jon.data=500;//rvalu
kevin=jon;
*jon.data=600;//rvalu
cout<<*kevin.data; //kevin printin 600 but it should be print 500; so i want to use move
return 0;
}
Comments
Post a Comment