- How to properly return std::string (or how to properly use that returned value)
- class MyClass {
- protected:
- std::string m_Value;
- public:
- MyClass () : m_Value("hello") {}
- std::string value() { return m_Value; }
- };
- MyClass v1;
- printf("value: %sn", v1.value().c_str());
- std::string copiedString = v1.value();
- printf("value: %sn", copiedString.c_str());
- std::string value() const { return m_value; }