【问题标题】:std - including <initializer_list> or creating my own definition of it causes C2953 error when compilingstd - 包括 <initializer_list> 或创建我自己的定义会在编译时导致 C2953 错误
【发布时间】:2020-03-05 15:30:53
【问题描述】:

我正在尝试将 EASTL 用于我正在处理的项目,它无法编译,我能找到的唯一错误来自它的“EASTL/initializer_list.h”,我正在使用最新版本的这个文件。出现的 2 个错误是 C2953 和另一个告诉我查看其定义的错误。 EASTL 会自动禁用包含此文件时出现的所有警告,甚至有自己的定义以在其文件中使用。唯一的问题是这包含了文件的 Windows 版本,它仍然会导致错误,即使它应该包含就好了?我正在使用 C++14,我的平台工具集是 v142 (Visual Studio 2019),我的 Windows SDK 版本是 10.0;我知道有人说要更新我已经完成的“EA_HAVE_CPP11_INITIALIZER_LIST 定义”,所以这不应该是问题。

这是导致错误的代码:

#if defined(EA_HAVE_CPP11_INITIALIZER_LIST) // If the compiler can generate calls to std::initializer_list...

// The initializer_list type must be declared in the std namespace, as that's the 
// namespace the compiler uses when generating code to use it.
EA_DISABLE_ALL_VC_WARNINGS()
#include <initializer_list>
EA_RESTORE_ALL_VC_WARNINGS()

#else

// If you get an error here about initializer_list being already defined, then the         EA_HAVE_CPP11_INITIALIZER_LIST define from <EABase/eahave.h> needs to be updated.
namespace std
{
    // See the C++11 Standard, section 18.9.
    template<class E>
    class initializer_list
    {
    public:
        typedef E         value_type;
        typedef const E& reference;
        typedef const E& const_reference;
        typedef size_t    size_type;
        typedef const E* iterator;             // Must be const, as initializer_list (and its mpArray) is an immutable temp object.
        typedef const E* const_iterator;

    private:
        iterator  mpArray;
        size_type mArraySize;

        // This constructor is private, but the C++ compiler has the ability to call it, as per the C++11 Standard.
        initializer_list(const_iterator pArray, size_type arraySize)
            : mpArray(pArray), mArraySize(arraySize) { }

    public:
        initializer_list() EA_NOEXCEPT  // EA_NOEXCEPT requires a recent version of EABase.  
            : mpArray(NULL), mArraySize(0) { }

        size_type      size()  const EA_NOEXCEPT { return mArraySize; }
        const_iterator begin() const EA_NOEXCEPT { return mpArray; }            // Must be const_iterator, as initializer_list (and its mpArray) is an immutable temp object.
        const_iterator end()   const EA_NOEXCEPT { return mpArray + mArraySize; }
    };
}

#endif

我尝试让它同时使用该类的 std 版本和该类的 EA 版本,这两者都会导致相同的错误 (C2953)。感谢您提供任何帮助,因为我希望能够尽快编译它!

【问题讨论】:

  • 您是否遵循“如果您在此处收到有关已定义初始化器列表的错误 [...]”评论中的建议?
  • 我刚刚编辑了这个问题,是的,我已经这样做了,它什么也没改变,不管它不应该,因为我强迫它使用这两个定义并且当前正在使用 windows 定义,它应该编译很好。
  • 请说明您是如何修改宏的。顺便说一句,我觉得有点奇怪,他们首先向std 添加了一些东西,看起来像是自找麻烦,现在你明白了
  • 我所做的只是将宏定义更新为最新的 eabase.h 文件,可以在这里找到:pastebin.com/ZKgFSbSq 我一直这么说,但我目前正在使用此类的 Windows STD 定义它仍然给出这个错误。此外,他们只会在找不到 std 命名空间时将自己的类版本添加到 std 命名空间中,他们并不打算在每次编译时都这样做。
  • 你是如何更新宏定义的?您如何强制它使用默认实现? (最简单的方法是将条件更改为#if 1。)

标签: c++ eastl


【解决方案1】:

在朋友的帮助下解决了,这是一个包含订单问题。

解决方法是将“EA_HAVE_CPP11_INITIALIZER_LIST”放入预处理定义列表中。

【讨论】:

    猜你喜欢
    • 2019-09-28
    • 1970-01-01
    • 2015-03-14
    • 2013-02-01
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    相关资源
    最近更新 更多