error C2665: “std::locale::facet::operator new”: 2 个重载中没有一个可以转换所有参数类型
qt项目 qt creator项目由插件自动转换成的vs2015项目,为了发布少带些dll ,切换成vs2013项目,在更改了一些vs2013不支持的c++新标准写法之后,release可正常编过,但是debug报错,具体如下
vs 报错:
DataManager.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(122): error C2665: “std::locale::facet::operator new”: 2 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(125): 可能是“void *std::locale::facet::operator new(size_t,const std::_DebugHeapTag_t &,char *,int)”
1> 尝试匹配参数列表“(size_t, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(758): error C2665: “operator new[]”: 5 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xdebug(37): 可能是“void *operator new[](size_t,const std::_DebugHeapTag_t &,char *,int) throw(...)”
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdbg.h(1080): 或 “void *operator new[](size_t,int,const char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(794): error C2665: “operator new[]”: 5 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xdebug(37): 可能是“void *operator new[](size_t,const std::_DebugHeapTag_t &,char *,int) throw(...)”
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdbg.h(1080): 或 “void *operator new[](size_t,int,const char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(1652): error C2665: “std::locale::facet::operator new”: 2 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(125): 可能是“void *std::locale::facet::operator new(size_t,const std::_DebugHeapTag_t &,char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(1887): error C2665: “std::locale::facet::operator new”: 2 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(125): 可能是“void *std::locale::facet::operator new(size_t,const std::_DebugHeapTag_t &,char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(2473): error C2665: “std::locale::facet::operator new”: 2 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(125): 可能是“void *std::locale::facet::operator new(size_t,const std::_DebugHeapTag_t &,char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(2669): error C2665: “std::locale::facet::operator new”: 2 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(125): 可能是“void *std::locale::facet::operator new(size_t,const std::_DebugHeapTag_t &,char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(2896): error C2665: “std::locale::facet::operator new”: 2 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(125): 可能是“void *std::locale::facet::operator new(size_t,const std::_DebugHeapTag_t &,char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xiosbase(455): error C2665: “operator new”: 5 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xdebug(33): 可能是“void *operator new(size_t,const std::_DebugHeapTag_t &,char *,int) throw(...)”
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdbg.h(1072): 或 “void *operator new(size_t,int,const char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [72], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xiosbase(537): error C2665: “operator new”: 5 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xdebug(33): 可能是“void *operator new(size_t,const std::_DebugHeapTag_t &,char *,int) throw(...)”
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdbg.h(1072): 或 “void *operator new(size_t,int,const char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [72], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xiosbase(591): error C2665: “operator new”: 5 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xdebug(33): 可能是“void *operator new(size_t,const std::_DebugHeapTag_t &,char *,int) throw(...)”
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdbg.h(1072): 或 “void *operator new(size_t,int,const char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [72], int)”时
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocnum(65): error C2665: “operator new[]”: 5 个重载中没有一个可以转换所有参数类型
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xdebug(37): 可能是“void *operator new[](size_t,const std::_DebugHeapTag_t &,char *,int) throw(...)”
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\crtdbg.h(1080): 或 “void *operator new[](size_t,int,const char *,int)”
1> 尝试匹配参数列表“(unsigned int, const std::_DebugHeapTag_t, const char [71], int)”时
----------------------------------------------------------------------------------------------------------------------------------
查了下 error C2665: “operator new[]”: 5 个重载中没有一个可以转换所有参数类型,对应的c2665 有如下两个解决方案:
from:http://blog.csdn.net/machh/article/details/43450725
解决方法1:注释掉以下代码:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
解决方法2:
将:代码中的#include <vector>移到stdafx.h的开头,也就是#program once的后面。
但并没有解决我的问题。
对比正常工程 发现c/c++ ->所有选项-->附加选项 多了-Zc:strictStrings ,应该是qt转换插件自动加的,去掉就可以正常编译了。
解释见:https://msdn.microsoft.com/zh-cn/library/dn449508.aspx
若要了解有关 Visual Studio 2017 RC 的最新文档,请参阅 Visual Studio 2017 RC 文档。
指定后,编译器要求通过使用字符串文本初始化的指针符合严格的 const
限定。
/Zc:strictStrings[-]
如果指定了 /Zc:strictStrings,则编译器针对字符串文本(如类型“const
char
的数组”或“const
wchar_t
的数组”,具体取决于声明)强制执行标准 C++ const
限定。 字符串文本不可变,并且尝试修改一个字符串文本的内容将导致在运行时出现访问冲突错误。 必须将字符串指针声明为 const
以通过使用字符串文本将其初始化,或使用显式 const_cast
以初始化非 const
指针。 或者默认情况下,如果指定了 /Zc:strictStrings-,则编译器不会针对通过使用字符串文本初始化的字符串指针强制执行标准 C++ const
限定。
使用 /Zc:strictStrings 选项来阻止编译错误代码。 此示例显示一个简单声明错误如何在运行时导致崩溃:
// strictStrings_off.cpp
// compile by using: cl /W4 strictStrings_off.cpp
int main() {
wchar_t* str = L"hello";
str[2] = L'a'; // run-time error: access violation
}
当 /Zc:strictStrings 处于启用状态时,相同的代码将报告 str
声明中的错误。
// strictStrings_on.cpp
// compile by using: cl /Zc:strictStrings /W4 strictStrings_on.cpp
int main() {
wchar_t* str = L"hello"; // error: Conversion from string literal
// loses const qualifier
str[2] = L'a';
}
如果使用 auto
声明字符串指针,则编译器将为你创建正确的 const
指针类型声明。 尝试修改 const
指针的内容将由编译器报告为错误。
![]() |
---|
Visual Studio 2013 中的 Visual C++ 中的标准 C++ 库不支持调试生成中的 /Zc:strictStrings 编译器选项。 如果在你的生成输出中看到多个 C2665 错误,则可能由此原因造成。 |
有关 Visual C++ 中的一致性问题的详细信息,请参阅非标准行为。
在 Visual Studio 开发环境中设置此编译器选项
-
打开项目的“属性页”对话框。 有关详细信息,请参见使用项目属性。
-
选择 C/C++ 文件夹。
-
选择“命令行”属性页。
-
修改“附加选项”属性以包含
/Zc:strictStrings
,然后选择“确定”。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!