Advertisement
cosminBoaca

Untitled

Apr 23rd, 2015
191
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() {
  8. cout << "Default constructor" << endl;
  9. }
  10. Foo(int x) {
  11. cout << "Constructor that takes int" << endl;
  12. this->x = x;
  13. }
  14. Foo(const Foo& other) {
  15. cout << "Copy constructor" << endl;
  16. this->x = other.x;
  17. }
  18. Foo& operator = (const Foo& other) {
  19. cout << "Assignment operator" << endl;
  20. this->x = other.x;
  21. }
  22. ~Foo() {
  23. cout << "Destructor" << endl;
  24. }
  25. };
  26.  
  27. int main() {
  28. Foo x;
  29. Foo y(2);
  30. Foo z(x);
  31. Foo t = z;
  32. Foo u;
  33. u = t;
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement