Skip to content

Instantly share code, notes, and snippets.

@keon
Created June 12, 2016 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keon/68d0ddfc51609304a653b8a2f0656c73 to your computer and use it in GitHub Desktop.
Save keon/68d0ddfc51609304a653b8a2f0656c73 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
template <typename ObjectType>
class BaseClass{
public:
friend ObjectType;
int Increment(){
return obj.Increment();
}
int getStuff() const
{
return stuff;
}
private:
static int stuff;
ObjectType obj;
};
template<typename T>
int BaseClass<T>::stuff = 0;
class ObjectType{
public:
int Increment ()
{
return BaseClass<ObjectType>::stuff++;
};
};
int main () {
BaseClass<ObjectType> base;
base.Increment(); // should increase stuff by 1;
cout << base.getStuff() << endl;
base.Increment(); // should increase stuff by 1;
cout << base.getStuff() << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment