Created
June 12, 2016 09:28
-
-
Save keon/68d0ddfc51609304a653b8a2f0656c73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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