简体   繁体   中英

What is the preprocessor define for C++ language in Xcode precompile header?

In my Prefix.pch file I am using __OBJC__ preprocessor define for compilation of Objective C headers. What is the equivalent for compilation of C++ headers?

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

There is a standard preprocessor constant, __cplusplus . Its value is expanded to version number of C++ standard being used:

__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)

Source: cppreference

So, you can write, for example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM