Note to self: next time a moment like this occurs, at least write about it in your weblog. Just yesterday, I was implementing simple singleton using technique from Scott Meyers most excellent Effective book series, where code goes something like this
class Singleton
{
public:
  static Singleton& instance()
  {
    static Singleton _this;
    return _this;
  }
protected:
  Singleton(...) { ... }
  ...
}
As code shows, trick is quite simple and easy to memorize except that you mustn't write it like this. In my infinite wisdom, I forgot that if I put the function in header, compiler will inline it and I will get an instance each time I invoke instance.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments