fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. class B{};
  5. class C : public B{};
  6. template <class T>
  7. class A {
  8. public:
  9. A(T * p) : ptr(p) {}
  10. A & operator = ( A && p){
  11. swap (p.ptr, ptr );
  12. return *this;
  13. }
  14. void pr(){cout<<*ptr<<endl;}
  15. private:
  16. T * ptr;
  17. int ai;
  18. };
  19. int main(){
  20. int a=5;
  21. int *p1=&a;
  22. //A <B> pa2(new C);
  23. A <int *> pa1 (new int *(p1 ));
  24. // pa1.pr();
  25. A<int> aob1(p1);
  26. aob1.pr();
  27. int b=6;
  28. int *p2=&b;
  29. A<int> aob2(p2);
  30. aob2.pr();
  31. aob2=aob1;
  32. aob2.pr();
  33. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:31:10: error: use of deleted function ‘constexpr A<int>& A<int>::operator=(const A<int>&)’
     aob2=aob1;
          ^~~~
prog.cpp:7:7: note: ‘constexpr A<int>& A<int>::operator=(const A<int>&)’ is implicitly declared as deleted because ‘A<int>’ declares a move constructor or move assignment operator
 class A {
       ^
stdout
Standard output is empty