Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include "Constructors.h"
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. Animal animal1;
  8. animal1.setName("Klinton");
  9.  
  10. Animal animal2 = animal1;
  11. animal2.speak();
  12. animal2.setName("Freddy");
  13. animal2.speak();
  14.  
  15. return 0;
  16. }
  17.  
  18. #ifndef _CONSTRUCTORS_H_
  19. #define _CONSTRUCTORS_H_
  20. #include <string>
  21. class Animal {
  22. private:
  23. std::string name;
  24. public:
  25. Animal() { cout << "Animal created." << endl; }
  26. Animal(const Animal& other): name(other.name) { cout << "Animal created copying." << endl; }
  27. void setName(std::string name) { this->name = name; }
  28. void speak() const { cout << "My name is: " << name << endl; }
  29.  
  30. }
  31.  
  32. #endif // !_CONSTRUCTORS_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement