title: Segmentation fault trying to overload << operator
body: <p>Beginning with C++, I've written that simple piece of code, which is designed to serve as a (very basic) logger. This is mainly to try overloading operators.</p>
  
  <pre><code>class Logger {
  
    public:
      Logger() : _has_logged_something(false) { };
  
      template &lt;typename T&gt;
      friend Logger&amp; operator &lt;&lt;(Logger&amp; logger, T const &amp; value) {
        logger._has_logged_something = true;
        std::cerr &lt;&lt; value;
        return logger;
      };
  
    private:
      bool _has_logged_something;
  
  };
  </code></pre>
  
  <p>I need to remember when something has been loaded already, in the <code>_has_logged_something</code> instance variable. But this line is causing a very helpful <code>Segmentation fault (core dumped)</code> at runtime. Must be an obvious mistake, but I can't get it.</p>
  
  <p>--</p>
  
  <p><strong>Edit</strong></p>
  
  <p>As this doesn't seem to be a problem with this piece of code, here is how it is used to avoid using singletons (probably not the best code ever, but anyway).</p>
  
  <pre><code>#ifndef _BORDERS_COMMON_LOGGER_LOGGER_HH_INCLUDED
  #define _BORDERS_COMMON_LOGGER_LOGGER_HH_INCLUDED
  
  #include "common/log/logger.hh"
  #include "common/log/event.hh"
  
  namespace {
    static borders::common::log::Logger* _global_logger = NULL;
  }
  
  namespace borders {
  
    namespace common {
  
      namespace log {
  
        inline bool is_global_instance_initialized() {
          return _global_logger != NULL;
        };
  
        inline Logger&amp; get_global_instance() {
          if (_global_logger == NULL) _global_logger = new Logger;
          return *_global_logger;
        };
  
      } // namespace log
  
    } // namespace common
  
  } // namespace borders
  
  #define LOG_INFO() (borders::common::log::get_global_instance())
  
  #define LOG_START()
  #define LOG_STOP() \
    if (borders::common::log::is_global_instance_initialized()) \
      delete &amp;borders::common::log::get_global_instance(); \
    else \
      (void) 0;
  
  #endif // _BORDERS_COMMON_LOGGER_LOGGER_HH_INCLUDED
  </code></pre>
  
  <p>Given I try to run this with:</p>
  
  <pre><code>LOG_INFO() &lt;&lt; "Foo" &lt;&lt; "Bar"
  </code></pre>
  
  <p>Once again, the text gets written on console when I comment out the line I pointed out before.</p>