fork(1) download
  1. #include <iostream>
  2.  
  3. class alloc
  4. {
  5.  
  6. };
  7.  
  8. template <typename T, typename Alloc = alloc>
  9. class vector
  10. {
  11. public:
  12. void swap(vector<T,Alloc> &v) { std::cout << "swap()" << std::endl; }
  13. };
  14.  
  15.  
  16. template <typename T, typename Alloc>
  17. void swap(const vector<T,Alloc> &v1,const vector<T,Alloc> &v2)
  18. {
  19. v1.swap(v2);
  20. }
  21.  
  22. int main()
  23. {
  24. vector<int> x;
  25. vector<int> y;
  26.  
  27. swap(x,y);
  28.  
  29. return 0;
  30. }
  31.  
Compilation error #stdin compilation error #stdout 0s 3452KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'void swap(const vector<T, Alloc>&, const vector<T, Alloc>&) [with T = int; Alloc = alloc]':
prog.cpp:27:13:   required from here
prog.cpp:19:5: error: passing 'const vector<int>' as 'this' argument discards qualifiers [-fpermissive]
     v1.swap(v2);
     ^
prog.cpp:12:10: note:   in call to 'void vector<T, Alloc>::swap(vector<T, Alloc>&) [with T = int; Alloc = alloc]'
     void swap(vector<T,Alloc> &v) { std::cout << "swap()" << std::endl; }
          ^
prog.cpp:19:5: error: binding 'const vector<int>' to reference of type 'vector<int>&' discards qualifiers
     v1.swap(v2);
     ^
prog.cpp:12:10: note:   initializing argument 1 of 'void vector<T, Alloc>::swap(vector<T, Alloc>&) [with T = int; Alloc = alloc]'
     void swap(vector<T,Alloc> &v) { std::cout << "swap()" << std::endl; }
          ^
stdout
Standard output is empty