65,190
社区成员




代码简单描述如下:
template <bool> struct compiletime;
template<> struct compiletime<true>
{
compiletime(...) {}
};
template <> struct compiletime<false> {};
struct ERROR{};
compiletime<sizeof(char)>=sizeof(int)>(ERROR()); //测试代码出现编译警告
warning C4930: 'compiletime<false> ERROR(void)': prototyped function not called
(was a variable definition intended?)
ERROR(void)函数没有被调用是何意?并且被编译器调侃为故意作为局部变量
int();
int(6);
template <bool>
struct compiletime;
template<>
struct compiletime<true>
{
compiletime(...) {}
};
struct ERROR{};
template <>
struct compiletime<false>{
compiletime(ERROR ) {}
};
int _tmain(int argc, _TCHAR* argv[])
{
compiletime<sizeof(char)>=sizeof(int)>::compiletime(ERROR());
return 0;
}
谢谢荣哥、Jinhao、 yshuise 以及道兄,每次我发贴的问题荣哥都不遗余力地给予帮助真是非常的感谢,确实
此类代码在实际的工作中凤毛麟角,不但生涩而且难懂,考验编译器的能力本身就是编码工作中的不幸,更何况
像模板这种不具备良好移植性的代码尤其如此。
受教了,再次感谢!!!
int (foo())
{
return 0;
}
int main()
{
int i = foo();
}