Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 6th, 2012  |  syntax: None  |  size: 0.43 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to properly return std::string (or how to properly use that returned value)
  2. class MyClass {
  3.   protected:
  4.     std::string m_Value;
  5.   public:
  6.     MyClass () : m_Value("hello") {}
  7.     std::string value() { return m_Value; }      
  8. };
  9.  
  10. MyClass v1;
  11.        
  12. printf("value: %sn", v1.value().c_str());
  13.        
  14. std::string copiedString = v1.value();
  15.    printf("value: %sn", copiedString.c_str());
  16.        
  17. std::string value() const { return m_value; }