简体   繁体   中英

std::tr1 with visual studio 2017

I have some C++ code that uses some version of Google's GTest framework. This code used to compile fine with Visual Studio 2015. I just upgraded to VS2017, and now I get a bunch of errors like this:

error C2039: 'tr1': is not a member of 'std'
error C3083: 'tr1': the symbol to the left of a '::' must be a type

Is some compiler option needed to use std::tr1 in VS2017?

One option is to re-enable TR1; do this by defining the macro _HAS_TR1_NAMESPACE , as briefly mentioned in this blog article . If you're using an MSBuild project then this is best done by way of your project's Preprocessor Definitions setting; or if you're using a precompiled header, by defining it at the top of said PCH.

A better option is to inform GTest that your compiler supports C++11 by defining the macro GTEST_LANG_CXX11 to 1 before including any GTest headers; then it will use std::tuple rather than std::tr1::tuple *. ( GTest's C++11-detection logic is __cplusplus -oriented, which VC++ has not yet updated despite being mostly C++11 and C++14 compliant. I would say this is a bug in GTest since it supports VC++ elsewhere throughout the configuration logic.)

* Not to mention the other C++11 features, which is why this is by far the better option ;-]

Googletest1.8.1 版修复了这个问题(结合 VS2017 15.8.5)。

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