Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
temporaries and move constructor
// Example program #include <iostream> #include <string> class Movable { public: int x; Movable(){ std::cout << "Constructor "; std::cout <<"This = " << this <<std::endl; } Movable(Movable&& rhs) { std::cout << "Move "; std::cout <<"This = " << this <<std::endl; } Movable(const Movable& rhs) { std::cout << "copy "; std::cout <<"This = " << this <<std::endl; } const Movable& operator=(const Movable& r) { std::cout << "assignment "; std::cout <<"This = " << this <<std::endl; return *this; } ~Movable() { std::cout<<"dest "; std::cout <<"This = " << this <<std::endl; } void printMe(char* msg) { std::cout <<msg <<" this: " << this << std::endl; } }; std::string returnStr() { return "STR"; } void fm(Movable&& tm) { std::cout << tm.x; Movable s = tm; } Movable rf(int i) { Movable lt; lt.printMe("[rf::lt]"); return lt; } void f(Movable m) { m.printMe("[f::me]"); Movable t = m; } int main() { int i = 8; //std::cin >> i; f(Movable{}); std::cout<<"----------"<<std::endl; f(rf(i)); return 0; }
run
|
edit
|
history
|
help
0
Menu Combination Sum
DeltaX campus recruitment
PhB
Bucket Graph Creation
rotation
Binary tree balanced or not
StackTel
Triplet sum in array
XML parsing with regex
HelloWorld