[ create a new paste ] login | about

Link: http://codepad.org/hhWRunbl    [ raw code | output | fork ]

C++, pasted on Mar 24:
// study template
#include <iostream>

template<typename T>
class TFoo{
private:
    T val_;
public:
    TFoo(){ std::cout << "TFoo" << std::endl; }
};

typedef TFoo<int> Foo;

class Hoge{
public:
    Hoge(){ std::cout << "Hoge" << std::endl; }
};

class Factory{
public:
    template<typename T>
    TFoo<T> create(){ return TFoo<T>(); }
    Foo create(){ return Foo(); }
};

int main (int argc, char * const argv[]) {
    Factory fac;
    TFoo<Hoge> hoge = fac.create<Hoge>();
    Foo foo = fac.create();
	
    return 0;
}


Output:
1
2
3
Hoge
TFoo
TFoo


Create a new paste based on this one


Comments: