Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. template <typename T>
  2. class ExtendedType
  3. {
  4. public:
  5.     T object;
  6. ExtendedType(const T & source) : object(source){std::cout<<"konstruktor przyjmujacy stala referencje do T\n";}
  7. ExtendedType(T && source) : object(std::move(source)){std::cout<<"konstruktor przenoszacy: "<<object<<"\n";}
  8. ...
  9. }
  10.  
  11. class Foo
  12. {
  13. public:
  14.     ExtendedType<int> obj;
  15.     Foo(int x = 1234) : obj(x){std::cout<<"domyslny Foo \n";}
  16.     ...
  17. }
  18.  
  19. int main()
  20. {
  21.     Foo a(5);                           // wypisuje: konstruktor przyjmujacy stala referencje do T
  22.     ExtendedType<int> b(10);            // wypisuje: konstruktor przenoszacy obiekt: 10
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement