不能包含 在我的mfc应用程序中,编译器错误

问题描述 投票:0回答:1

不久前,我将MFC应用程序移至C ++ 17,一切都很好。我想使用std::to_chars,因此包含在cpp文件中。没用试图将其放在StdAfx.h的早期,同样的错误。

然后,我在控制台应用程序中进行了尝试,即使我添加了MFC应用程序中使用的大量头文件,也不会收到错误消息。错误是某些标头包括冲突,它们仅在编译StdAfx.h时出现。即使我将它作为StdAfx.h中的第一个文件,它也会发生。我已经在两个项目的属性之间进行了制表,并且出于所有实际目的,它们是相同的。

UPDATE

我正在使用:SDK 10.0(最新安装版本)Visual Studio 2019(v142)版本16.4.2ISO C ++ 17标准(std:c ++ 17)

在控制台应用程序中,无论是否使用预编译的标头,我都尝试过它,并且它可以双向工作。我已经发布了完整的错误消息,并包含在一个cpp文件中。

我想知道我的项目文件中是否藏有某些东西。从VS6成长至今已20岁。现在,我将仅使用auto str(std::to_wstring(cur));。下一步是创建一个干净的项目并将我的应用程序源复制到该项目。无论如何,都需要尝试一下,因为它可能会解决this,但我仍然无法使用向导添加变量。

错误正在编译<charconv>

\charconv(1503,68): error C2672: 'std::_Max_value': no matching overloaded function found
\charconv(1912): message : see reference to function template instantiation 'std::errc std::_Convert_decimal_string_to_floating_type<_Floating>(const std::_Floating_point_string &,_FloatingType &,bool) noexcept' being compiled
1>        with
1>        [
1>            _Floating=float,
1>            _FloatingType=float
1>        ]
\charconv(2053): message : see reference to function template instantiation 'std::from_chars_result std::_Ordinary_floating_from_chars<_Floating>(const char *const ,const char *const ,_Floating &,const std::chars_format,const bool,const char *) noexcept' being compiled
1>        with
1>        [
1>            _Floating=float
1>        ]
\charconv(2065): message : see reference to function template instantiation 'std::from_chars_result std::_Floating_from_chars<float>(const char *const ,const char *const ,_Floating &,const std::chars_format) noexcept' being compiled
1>        with
1>        [
1>            _Floating=float
1>        ]
\charconv(1503,1): error C2782: 'const _Ty &std::_Max_value(const _Ty &,const _Ty &) noexcept(<expr>)': template parameter '_Ty' is ambiguous
\utility(35): message : see declaration of 'std::_Max_value'
\charconv(1503,1): message : could be 'int32_t'
\charconv(1503,1): message : or       'int'
\charconv(1503,1): error C2784: 'const _Ty &std::_Max_value(const _Ty &,const _Ty &) noexcept(<expr>)': could not deduce template argument for 'const _Ty &' from 'const int32_t'
\utility(35): message : see declaration of 'std::_Max_value'
\charconv(1503,44): error C2789: '_Positive_exponent': an object of const-qualified type must be initialized
\charconv(1503): message : see declaration of '_Positive_exponent'

我添加到控制台应用程序的标头,但没有产生问题:

#include <boost/date_time/gregorian/greg_date.hpp>
#include <boost/locale.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/spirit/home/x3.hpp>
#include <SDKDDKVer.h>
#include <intsafe.h>
#include <afxwin.h>         // MFC core and standard components
#include <charconv>
#include <afxrich.h>        // MFC Rich Edit Control used in most.
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdb.h>          // ODBC support
#include <afxdtctl.h>       // MFC support for Internet Explorer 4 Common Controls
#include <afxcmn.h>         // MFC support for Windows Common Controls
#include <afxcview.h>       // MFC Common controls
#include <afxdhtml.h>       // html support
#include <afxdlgs.h>        // Common Dialogs
#include <afxtempl.h>       // MFC template support.
#include <atlimage.h>       // GDIPlus, not....
#include <raserror.h>       // ERROR_ defines
#include <direct.h>         // for _tchdir( GetProjectDirectory( ) );
#include <shlobj.h>         // SHGetFolderPath(...)
#include <afxdialogex.h>    //for ReTreeDlg
#include <gdiplus.h>        // GDIPlus
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
#include <boost/asio/connect.hpp>
#include <boost/bind.hpp>
#include <boost/exception/exception.hpp>
#include <boost/thread.hpp>
#include <boost/variant.hpp>
#include <boost/lexical_cast.hpp>

[十分之九,我会在写问题时弄清楚。这是一次,我很茫然。只是希望有人以前看到过这种情况。

c++ mfc c++17
1个回答
0
投票

这完全是我的工作。原来,在我的其他包含路径之一中,我有一个旧的stdint.h。编译器会在SDK中找到较新的版本之前先进行选择。在我尝试并入charconv之前,一切正常就足够了。它的日期是2012年,我把它放在了VS2010的一部分中。

因此,教训是,如果发生类似这样的奇怪冲突,请确保检查您是否做过一些愚蠢的事情,例如将文件放在您自己的include中,但不应将其放在那里。这样做今天可能会解决某些问题,但可能会中断几年的工作。

© www.soinside.com 2019 - 2024. All rights reserved.