0

在我的Prefix.pch文件中,我使用__OBJC__预处理器定义来编译 Objective C 头文件。编译 C++ 头文件的等价物是什么?

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
#endif
4

1 回答 1

2

有一个标准的预处理器常量,__cplusplus. 它的值扩展为正在使用的 C++ 标准的版本号:

__cplusplus

表示正在使用的 C++ 标准的版本,扩展为值 199711L(直到 C++11)、201103L (C++11)、201402L (C++14) 或 201703L (C++17)

资料来源:cppreference

因此,您可以编写,例如:

#ifdef __cplusplus
  #if __cplusplus >= 201103L
    // include new stuff
  #else
    // use legacy features
  #endif
#endif
于 2017-12-07T12:10:45.757 回答