class template and construct function template

Template
#include <iostream>

using namespace std;

template
<
typename TClassType
>
class TClass {
public:

template
<
typename TFuncType
>
TClass( TClassType var1, TFuncType var2) { mVar
= var1 * var2; }

template
<
typename TFuncType
>
TClass( TClassType var1, TFuncType var2, TFuncType var3) { mVar
= var1 * ( var2 + var3); }

void printTo() { cout << mVar << endl; }
protected:
private:
TClassType mVar;
};



int
main(
int argc, char **argv) {

TClass
< int > inst( 1024, 2.2, 2.8);

inst.printTo();

return 0;
}
posted @ 2011-05-13 15:45  soulnearby  阅读(132)  评论(0编辑  收藏  举报