0
Why not move constructor
I was expecting move constructor . Why not? https://sololearn.com/compiler-playground/cAbUWJKaaQa2/?ref=app
6 odpowiedzi
+ 1
Ketan Lalcheta Your code does not try to move or copy your test class object to any other variable.
Your display() function calls the constructor as part of resolving the function argument and assigns it to the obj variable inside the display() method.
You don't do anything else with the object at that point, so the destructor is called when the display() method ends and the scope closes.
+ 1
maybe specifically use move?
int main()
{
test t;
display(test(move(t)));
return 0;
}
+ 1
But test is temporary object meaning it is already the r value Bob_Li
0
Shardis Wolfe I don't want to perform any operation on object , so destructor is okay for me.
As test() is not named value and hence not a lvalue, it is a r value . So, it should not call constructor , but should map to move constructor. Isn't my understanding correct?
0
just because it's an r value is not enough reason for it to be moved. as it is in your code, it's just a function argument.
0
Do you mean to say r value does not call move and move is only called if it was made r value forcefully by making use of std::move?