Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBacterius

Posted 21 October 2012 - 03:55 PM

[source lang="cpp"]class DebugLog {public:DebugLog();~DebugLog();string writeTo(string text);private:string m_Text;string m_Filename;ofstream m_debugLog;};DebugLog::DebugLog(){ m_debugLog.open("DebugLog.txt"); // m_debuglog now belongs to the class, not just the constructor // so it can be accessed in writeTo() as well}[/source]

This means the debugLog object is now attached to your class instead of a specific method, so every method in the class has now access to it. The constructor takes care of creating the stream. Does it make more sense now?

Never mind the destructor stuff for now - you need to understand the concept of class fields before.

#1Bacterius

Posted 21 October 2012 - 03:52 PM

[source lang="cpp"]class DebugLog { public: DebugLog(); ~DebugLog(); string writeTo(string text); private: string m_Text; string m_Filename; ofstream m_debugLog; };DebugLog::DebugLog(){ m_debugLog = ofstream("DebugLog.txt"); // m_debuglog now belongs to the class, not just the constructor // so it can be accessed in writeTo() as well}[/source]

This means the debugLog object is now attached to your class instead of a specific method, so every method in the class has now access to it. The constructor takes care of creating the stream. Does it make more sense now?

Never mind the destructor stuff for now - you need to understand the concept of class fields before.

PARTNERS