The program
#include<iostream>
using namespace std;
struct abhi{
int a=2;
int b=1;
~abhi(){cout<<"destroyed"<<endl;}
};
void su(int a, int b, abhi&& ptr){
cout<<"yes"<<endl;
}
int main(){
abhi ptr;
su(1,2,move(ptr));
cout<<"after"<<endl;
}
The Output
yes
after
destroyed
Shouldnt the destructor be called inside the su
function as I using move
to pass the ptr
.
I have used move
operator with unique_ptr
and it used to pass the ownership completely, so I am getting different result with plain pointer
.