Advertisement
kamiakze

cpp00

Mar 27th, 2023
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Warlock {
  5. public:
  6. Warlock(std::string name, std::string title) : m_name(name), m_title(title) {
  7. std::cout << m_name << ": This looks like another boring day.\n";
  8. }
  9.  
  10. Warlock(const Warlock&) = delete;
  11. Warlock& operator=(const Warlock&) = delete;
  12.  
  13. const std::string& getName() const { return m_name; }
  14. const std::string& getTitle() const { return m_title; }
  15. void setTitle(const std::string& title) { m_title = title; }
  16.  
  17. void introduce() const {
  18. std::cout << m_name << ": I am " << m_name << ", " << m_title << "!\n";
  19. }
  20.  
  21. ~Warlock() {
  22. std::cout << m_name << ": My job here is done!\n";
  23. }
  24.  
  25. private:
  26. std::string m_name;
  27. std::string m_title;
  28. };
  29.  
  30. int main() {
  31. // This will not compile
  32. // Warlock bob;
  33.  
  34. Warlock bob("Bob", "the magnificent");
  35. Warlock jim("Jim", "the nauseating");
  36.  
  37. // This will not compile
  38. // bob = jim;
  39.  
  40. // This will not compile
  41. // Warlock jack(jim);
  42.  
  43. bob.introduce();
  44. jim.introduce();
  45.  
  46. bob.setTitle("the wizard");
  47. jim.setTitle("the destroyer");
  48.  
  49. bob.introduce();
  50. jim.introduce();
  51.  
  52. return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement