fork download
  1. #include <iostream>
  2.  
  3. class myclass{
  4. public:
  5. myclass(const myclass &other){std::cout << "copy\n";}
  6. myclass(myclass &&other){std::cout << "move\n";}
  7.  
  8. myclass(myclass &rhs):
  9. myclass(static_cast<const myclass&>(rhs))
  10. {std::cout << "-> with forward\n";}
  11.  
  12.  
  13. template<typename Special>
  14. myclass(Special &&arg){std::cout << "special\n";}
  15. };
  16.  
  17. int main() {
  18. const myclass c1(42); // special: int
  19. myclass c2(c1); // copy
  20. myclass c3(c2); // copy (with forward)
  21. myclass c4(std::move(c3)); // move
  22.  
  23.  
  24. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
special
copy
copy
-> with forward
move