h**********c 发帖数: 4120 | 1 Try to figure it out but failed,as the following:
void takefloat (float * ) {}
void takedouble (double *) {}
template
void dosomething (T * pt)
{
#if sizeof(T) == sizeof(float)
takefloat (pt);
#else
takedouble(pt);
#endif
}
Compilation failed. |
|
t****t 发帖数: 6806 | 2 for metaprogramming, there is no "if". condition is always implicit. for
your example (as a simple function), you should write:
void dosomething(float* pt) { takefloat(pt); }
template void dosomething(T* pt) { takedouble(pt); }
although you may really want to write
void dosomething(float* pt) { takefloat(pt); }
void dosomething(double* pt) { takedouble(pt); } |
|
h**********c 发帖数: 4120 | 3 Try to figure it out but failed,as the following:
void takefloat (float * ) {}
void takedouble (double *) {}
template
void dosomething (T * pt)
{
#if sizeof(T) == sizeof(float)
takefloat (pt);
#else
takedouble(pt);
#endif
}
Compilation failed. |
|
t****t 发帖数: 6806 | 4 for metaprogramming, there is no "if". condition is always implicit. for
your example (as a simple function), you should write:
void dosomething(float* pt) { takefloat(pt); }
template void dosomething(T* pt) { takedouble(pt); }
although you may really want to write
void dosomething(float* pt) { takefloat(pt); }
void dosomething(double* pt) { takedouble(pt); } |
|
h*******s 发帖数: 8454 | 5 好像这样就可以了
怎么还用#来注释啊。。。
takefloat ((float *)pt);
takedouble((double *)pt); |
|
h*******s 发帖数: 8454 | 6 好像这样就可以了
怎么还用#来注释啊。。。
takefloat ((float *)pt);
takedouble((double *)pt); |
|