Advertisement
cosminBoaca

Untitled

Apr 23rd, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo {
  5. int x;
  6. public:
  7. Foo() : x(0) {
  8. cout << "Default constructor" << endl;
  9. }
  10. Foo(int x) : x(x) {
  11. cout << "Constructor that takes int" << endl;
  12. }
  13. Foo(const Foo& other) : x(other.x) {
  14. cout << "Copy constructor" << endl;
  15. }
  16. Foo& operator = (const Foo& other) {
  17. cout << "Assignment operator" << endl;
  18. this->x = other.x;
  19. return *this;
  20. }
  21. ~Foo() {
  22. cout << "Destructor" << endl;
  23. }
  24. };
  25.  
  26. int main() {
  27. Foo x;
  28. Foo y(2);
  29. Foo z(x);
  30. Foo t = z;
  31. Foo u;
  32. u = t;
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement