gpt4 book ai didi

c++ - Xcode 预编译 header 中为 C++ 语言定义的预处理器是什么?

转载 作者:行者123 更新时间:2023-11-28 01:39:53 24 4
gpt4 key购买 nike

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

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

最佳答案

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

__cplusplus

denotes the version of C++ standard that is being used, expands to value 199711L (until C++11), 201103L (C++11), 201402L (C++14), or 201703L (C++17)

来源:cppreference

所以,你可以这样写,例如:

#ifdef __cplusplus
#if __cplusplus >= 201103L
// include new stuff
#else
// use legacy features
#endif
#endif

关于c++ - Xcode 预编译 header 中为 C++ 语言定义的预处理器是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47694744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com