Guest User

Untitled

a guest
Oct 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. class OtherClass {
  5. public:
  6. void setOtherMember() {
  7. m_otherMember = 2;
  8. std::cout << "Other member is now 2" << std::endl;
  9. }
  10.  
  11. private:
  12. int m_otherMember = 0;
  13. };
  14.  
  15.  
  16. class TestClass {
  17. public:
  18. TestClass(): m_otherClass(std::make_unique<OtherClass>())
  19. // TestClass()
  20. {}
  21.  
  22. void myMethod() const {
  23. m_otherClass->setOtherMember();
  24. // m_otherClass.setOtherMember();
  25. }
  26. private:
  27. std::unique_ptr<OtherClass> m_otherClass;
  28. // OtherClass m_otherClass; // If changing to this I get the error!!
  29. };
  30.  
  31.  
  32. int main() {
  33. TestClass testClass;
  34. testClass.myMethod();
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment