#include <fstream>
#include <vector>
#include <list>
#include <math.h>
#include <iostream>
#include <memory>
using namespace std;
template <class T>
class Factory {
protected:
int num;
public:
Factory(int num) : num(num) {}
virtual T * create() {
return new T(num);
}
};
class Integer {
int num;
public:
Integer(int num) : num(num) {}
};
class Pair {
int num1, num2;
public:
Pair(int num1, int num2 = 42) : num1(num1), num2(num2) {}
};
class ExtendedFactory : public Factory<Pair> {
protected:
int num2;
public:
ExtendedFactory(int num1, int num2) : Factory(num1), num2(num2) {}
virtual Pair * create() {
return new Pair(num, 24);
}
};
int main()
{
Factory<Integer> ints(42);
ints.create();
return 0;
}
I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxtZW1vcnk+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0ZW1wbGF0ZSA8Y2xhc3MgVD4KY2xhc3MgRmFjdG9yeSB7CnByb3RlY3RlZDoKICAgIGludCBudW07CnB1YmxpYzoKICAgIEZhY3RvcnkoaW50IG51bSkgOiBudW0obnVtKSB7fQogICAgdmlydHVhbCBUICogY3JlYXRlKCkgewogICAgICAgIHJldHVybiBuZXcgVChudW0pOwogICAgfQp9OwoKY2xhc3MgSW50ZWdlciB7CiAgICBpbnQgbnVtOwpwdWJsaWM6CiAgICBJbnRlZ2VyKGludCBudW0pIDogbnVtKG51bSkge30KfTsKCmNsYXNzIFBhaXIgewogICAgaW50IG51bTEsIG51bTI7CnB1YmxpYzoKICAgIFBhaXIoaW50IG51bTEsIGludCBudW0yID0gNDIpIDogbnVtMShudW0xKSwgbnVtMihudW0yKSB7fQp9OwoKY2xhc3MgRXh0ZW5kZWRGYWN0b3J5IDogcHVibGljIEZhY3Rvcnk8UGFpcj4gewpwcm90ZWN0ZWQ6CiAgICBpbnQgbnVtMjsKcHVibGljOgogICAgRXh0ZW5kZWRGYWN0b3J5KGludCBudW0xLCBpbnQgbnVtMikgOiBGYWN0b3J5KG51bTEpLCBudW0yKG51bTIpIHt9CiAgICB2aXJ0dWFsIFBhaXIgKiBjcmVhdGUoKSB7CiAgICAgICAgcmV0dXJuIG5ldyBQYWlyKG51bSwgMjQpOwogICAgfQp9OwoKaW50IG1haW4oKQp7CiAgICBGYWN0b3J5PEludGVnZXI+IGludHMoNDIpOwogICAgaW50cy5jcmVhdGUoKTsKICAgIHJldHVybiAwOwp9