fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct Your_Object
  6. {
  7. Your_Object& operator=(const Your_Object& other)
  8. {
  9. // Write a proper assignment operator here
  10. cout << "hello from assignment operator"<<endl;
  11. return *this;
  12. }
  13. };
  14.  
  15. int main() {
  16.  
  17. Your_Object nullObj;
  18. std::vector<Your_Object> vec;
  19. vec.reserve(10); // Creates 10 empty objects calling default constructors
  20.  
  21. Your_Object space5, space3; // Two objects to put in space5 and space3
  22.  
  23. // Put objects in space 5 and 3
  24. vec[5] = space5;
  25. vec[3] = space3;
  26.  
  27. // Move object in space 5 to another place
  28. vec[1] = vec[5];
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
hello from assignment operator
hello from assignment operator
hello from assignment operator