先贴代码:
#include
<
stdio.h
>

template
<
int
v
>
struct
Int2Type
{
enum { value = v };
}
;

void
func(Int2Type
<
true
>
)
{
printf("true ");
}

void
func(Int2Type
<
false
>
)
{
printf("false ");
}

template
<
bool
value
>
void
func()
{
func(Int2Type<value>());
}

int
main()
{
func<true>();
func<false>();
return 1;
}
上一例子是在同一函数中实现条件编译,而本例是通过函数重载来实现条件编译。






























