Here is a Selfie C++ class example.

AKA Singleton (because “Selfie is so 2013″, people are saying).

// Ego.h
class Ego
{
public:
  static Ego *Selfie();

  uint32_t GetLikes() const { return mLikes; }
  void Like() { ++mLikes; }

private:
  uint32_t mLikes;

  Ego() : mLikes(0) { }
  Ego(const Ego&);
  Ego& operator=(const Ego&);
  ~Ego() { }
};

// Ego.cpp
Ego *Ego::Selfie()
{
  static Ego selfie;
  return &selfie;
}

// anywhere_you_go.cpp
#include "Ego.h"
Ego::Selfie()->Like();
Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>