#include <iostream>
using namespace std;
// - templateexample.h
template<typename T> class Example
{
public:
Example(){}
int doWork() {return 42;}
};
// ---------------------------
// - templatespecialization.h
//#include "templateexample.h"
template<> class Example<int>
{
public:
Example() : a(0), b(1), c(2), d(3) {}
int doWork() {return a+b+c+d;}
private:
int a;
int b;
int c;
int d;
};
// ---------------------------
// - a.h ---------------------
// #include templateexample.h
class A
{
public:
Example<int> returnSmallExample();
};
// - a.cpp -------------------
Example<int> A::returnSmallExample() {return Example<int>();}
// ---------------------------
// - main.cpp ---------------
// #include "a.h"
// #include "templatespecialization.h"
int main()
{
A a;
Example<int> test = a.returnSmallExample();
std::cout<<test.doWork()<<std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy8gLSB0ZW1wbGF0ZWV4YW1wbGUuaAp0ZW1wbGF0ZTx0eXBlbmFtZSBUPiBjbGFzcyBFeGFtcGxlCnsKCXB1YmxpYzoKCQlFeGFtcGxlKCl7fQoJCWludCBkb1dvcmsoKSB7cmV0dXJuIDQyO30KfTsKLy8gLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCgovLyAtIHRlbXBsYXRlc3BlY2lhbGl6YXRpb24uaAovLyNpbmNsdWRlICJ0ZW1wbGF0ZWV4YW1wbGUuaCIKdGVtcGxhdGU8PiBjbGFzcyBFeGFtcGxlPGludD4KewoJcHVibGljOgoJCUV4YW1wbGUoKSA6IGEoMCksIGIoMSksIGMoMiksIGQoMykge30gCgkJaW50IGRvV29yaygpIHtyZXR1cm4gYStiK2MrZDt9CgkJCglwcml2YXRlOgoJCWludCBhOwoJCWludCBiOwoJCWludCBjOwoJCWludCBkOwp9OwovLyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KCi8vIC0gYS5oIC0tLS0tLS0tLS0tLS0tLS0tLS0tLQovLyAjaW5jbHVkZSB0ZW1wbGF0ZWV4YW1wbGUuaApjbGFzcyBBCnsKCXB1YmxpY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