fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Example {
  5. Example(int x) {
  6. cout << "Constructor!" << endl;
  7. }
  8. Example& operator=(int x) {
  9. cout << "Assignment!" << endl; return *this;
  10. }
  11. };
  12.  
  13. int main() {
  14. Example e = 1; // prints "Constructor!"
  15. e = 2; // prints "Assignment!"
  16. // The same symbol `=` actually does two different things
  17.  
  18. Example d{1}; // prints "Constructor!"
  19. //d{2}; // Error
  20. d = 2; // prints "Assignment!"
  21. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Constructor!
Assignment!
Constructor!
Assignment!