c++ - 错误: C2057: expected constant expression

标签 c++ windows visual-c++ compiler-errors qt-creator

我正在尝试构建最初在mingw之上制作的项目,但现在我们需要切换到MSVC++(因为特定的调试库仅支持该功能),但令我惊讶的是,即使在新的C++版本/Qt上编译该代码也会导致错误:

error: C2057: expected constant expression



错误不是我自己的源代码的一部分,而是qmetatype.h header 中的Qt本身,所以我不知道如何解决。我以为它缺少C++ 11标志,所以我添加了CONFIG += c++11并没有改变。然后,我尝试更具体,并在QMAKE_CXXFLAGS += /std:c++14文件中添加了.pro。同样的错误。错误行是:
struct CapabilitiesImpl<T, std::random_access_iterator_tag>
{ enum { IteratorCapabilities = RandomAccessCapability | BiDirectionalCapability | ForwardCapability }; };

注意:由于出现cl找不到错误,因此我从 qt.bat 文件中为Qt创建者加注星标,如下所示:
call "C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
"C:\Qt-MSVC\Qt5.7.1\Tools\QtCreator\bin\qtcreator.exe"

我该如何解决?

更新

我尝试使用一个较旧的版本来查看它是否具有任何区别,但没有,但是我得到了有关该错误的更多信息:

C:\Qt-MSVC\Qt5.5.0\5.5\msvc2013\include\QtCore\qmetatype.h:944: see reference to class template instantiation 'QtMetaTypePrivate::CapabilitiesImpl,std::random_access_iterator_tag>' being compiled C:\Qt-MSVC\Qt5.5.0\5.5\msvc2013\include\QtCore\qmetatype.h:1015: see reference to class template instantiation 'QtMetaTypePrivate::ContainerAPI' being compiled with [ T=QVariantList ] C:\Qt-MSVC\Qt5.5.0\5.5\msvc2013\include\QtCore\qvariant.h:711: see reference to function template instantiation 'QtMetaTypePrivate::QSequentialIterableImpl::QSequentialIterableImpl(const T *)' being compiled with [ T=QVariantList ]

最佳答案

使用MSVC编译器在QT中进行某些操作时,确实需要定义特定于MSVC的环境变量。因此,除非您自己手动定义这些环境变量,否则必须运行vcvarsall.bat

VCVarsall.bat is Visual Studio Command Prompt tool in Visual Studio. It's the tool that allows you to set various options for the integrated development environment (IDE) as well as build, debug, and deploy projects from the command line.

Source

关于c++ - 错误: C2057: expected constant expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49477421/

相关文章:

windows - 如何使用 Windows XP 中的内部选项在 VBScript 中解压缩文件

visual-studio - 自动创建 Visual C++ 故障转储

c++ - #include <fstream> visual c++ 2010 无法正常工作

c++ - 主线程和线程池

C++ 获取运行时间和内存使用情况

c++ - 为什么当我对数组使用增量操作时 for 循环不起作用

windows - 确定用于映射网络驱动器的域和用户名

c++ - std::unordered_map内部的std::array的值初始化

c# - AddFontResource() 在 Win10 周年更新时变慢

c++ - 异常在 MSVC 中的析构函数中抛出异常