我目前正在处理为Turbo C++设计的遗留代码。要解决Turbo C ++缺少bool
数据类型的问题,该程序包含以下代码行。
// Necessary when compiling with Turbo C++
enum bool {false, true};
大多数C ++编译器都无法使用error: expected identifier before 'bool'
运行程序。虽然我希望切换到更新的编译器,但遗憾的是我需要维护此解决方法以实现向后兼容性。
我怎么能指出这个特定的代码行只能在Turbo C ++中编译?
正如Thomas Matthews和selbie在评论中所建议的那样:
#ifdef __TURBOC__
// Only runs if compiler is Turbo C++
enum bool {false, true};
#endif
资料来源:http://beefchunk.com/documentation/lang/c/pre-defined-c/precomp.html