Advertisement
mbazs

C++ furcsasag (?)

Apr 1st, 2019
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include "pch.h" // ezt GNU g++-nal szedd ki!
  2. #include <iostream>
  3.  
  4. class A {
  5.     int _a;
  6. public:
  7.     A() : _a(55) {}
  8.     A(int const &a) : _a(a) { std::cout << "(1) ctor: " << a << std::endl; }
  9.     A(int const &&a) : _a(a) { std::cout << "(2) ctor: " << a << std::endl; }
  10.  
  11. };
  12.  
  13. int main()
  14. {
  15.     int x = 4;
  16.     A a0(x);
  17.     A a1(static_cast<int const&>(x));
  18.     A a2(static_cast<int const&&>(x));
  19.     A a3(static_cast<double const&>(x));
  20.     A a4(reinterpret_cast<int &&>(x));
  21.     A a5(reinterpret_cast<int const &>(x));
  22.     A a6(reinterpret_cast<int const &&>(x));
  23.     A a7(dynamic_cast<A&>(a0));
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement