Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- class OtherClass {
- public:
- void setOtherMember() {
- m_otherMember = 2;
- std::cout << "Other member is now 2" << std::endl;
- }
- private:
- int m_otherMember = 0;
- };
- class TestClass {
- public:
- TestClass(): m_otherClass(std::make_unique<OtherClass>())
- // TestClass()
- {}
- void myMethod() const {
- m_otherClass->setOtherMember();
- // m_otherClass.setOtherMember();
- }
- private:
- std::unique_ptr<OtherClass> m_otherClass;
- // OtherClass m_otherClass; // If changing to this I get the error!!
- };
- int main() {
- TestClass testClass;
- testClass.myMethod();
- return 0;
- }
Add Comment
Please, Sign In to add comment