由买买提看人间百态

topics

全部话题 - 话题: takedouble
(共0页)
h**********c
发帖数: 4120
1
来自主题: Programming版 - C++ template preprocessor
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
来自主题: Programming版 - C++ template preprocessor
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
来自主题: Programming版 - C++ template preprocessor
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
来自主题: Programming版 - C++ template preprocessor
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
来自主题: Programming版 - C++ template preprocessor
好像这样就可以了
怎么还用#来注释啊。。。

takefloat ((float *)pt);
takedouble((double *)pt);
h*******s
发帖数: 8454
6
来自主题: Programming版 - C++ template preprocessor
好像这样就可以了
怎么还用#来注释啊。。。

takefloat ((float *)pt);
takedouble((double *)pt);
(共0页)