Here is a Selfie C++ class example.

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

// Ego.h
class Ego
  static Ego *Selfie();

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

  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"
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>