title: Using operator const char* in ostream
body: <p>I am trying to Overload operator <code>&lt;&lt;</code> so the Error can be printed using <code>cout</code>. I need to print the <code>c-string</code> pointed by <code>m_messag</code>e. Can anyone help me solve this ? </p>
  
  <p><code>My Error.h</code> header :</p>
  
  <pre><code>ifndef ICT_ERROR_H_
  #define ICT_ERROR_H_
  
  #include &lt;iostream&gt;
  namespace ict {
     class Error {
        char* m_message;
     public:
     // constructors
         Error();
         Error(const char* errorMessage);
     // destructor
         virtual ~Error();
     // deleted constructor and operator=
         Error(const Error&amp; em) = delete;
         Error&amp; operator=(const Error&amp; em) = delete;
     // operator= for c-style strings
         void operator=(const char* errorMessage);
     // methods
         void clear();
         bool isClear()const;
         void message(const char* value);
     // cast overloads
         operator const char*() const;
         operator bool()const;
     };
     // operator &lt;&lt; overload prototype for cout
     std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Error&amp; E);
  }
  #endif
  
  Error.cpp
  
  #define _CRT_SECURE_NO_WARNINGS 
  #include &lt;cstring&gt;
  #include "Error.h"
  
  namespace ict{
      Error::Error()
      {
          m_message = nullptr;
      }
      Error::Error(const char * errorMessage)
      {
          m_message = nullptr;
          message(errorMessage);
  
      }
      Error::~Error()
      {
          delete[] m_message;
      }
      void Error::operator=(const char * errorMessage)
      {
          clear();
          message(errorMessage);
      }
      void Error::clear()
      {
          delete[] m_message;
          m_message = nullptr;
      }
      bool Error::isClear() const
      {
          bool status = false;
          if (m_message==nullptr) {
              status = true;
          }
          return status;
      }
      void Error::message(const char * value)
      {
          delete[] m_message;
          m_message = new char[strlen(value)+1];
          strcpy(m_message,value);
      }
      Error::operator const char*() const
      {
  
          return m_message;
      }
      Error::operator bool() const
      {
          return isClear();
      }
       ***std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Error&amp; E) {
          if (E.isClear()) {
  
          }
          return os &lt;&lt; E.operator const char *();
  
      }***
  }
  
  Main.cpp
  
  int main(){
    Error T("Testing Error Message"); 
    cout &lt;&lt; T &lt;&lt; endl ;
  
  }
  </code></pre>
  
  <p>When i execute it , it gives the correct output but it crashes with the following error :</p>
  
  <blockquote>
    <blockquote>
      <p>Exception thrown: read access violation.</p>
    </blockquote>
    
    <p>_First was nullptr.</p>
  </blockquote>
  
  <p>Debugger :</p>
  
  <pre><code> static size_t __CLRCALL_OR_CDECL length(const _Elem *_First)
              {   // find length of null-terminated string
     //next statement to be executed ---&gt; return (*_First == 0 ? 0
                   : _CSTD strlen(_First));
              }
  </code></pre>