C++ 为什么使用EnTT进程无法编译

C++ 为什么使用EnTT进程无法编译,c++,C++,下面我将对EnTT库3.2.2进行评估 使用VS2019社区版。它无法编译 #include <entt/entt.hpp> struct my_process : entt::process<my_process, std::int32_t> { using delta_type = std::uint32_t; void update(delta_type delta, void *) { remaining -= std::min(remaini

下面我将对EnTT库3.2.2进行评估

使用VS2019社区版。它无法编译

#include <entt/entt.hpp>

struct my_process : entt::process<my_process, std::int32_t> {
  using delta_type = std::uint32_t;

  void update(delta_type delta, void *) {
    remaining -= std::min(remaining, delta);

    if (!remaining) {
      succeed();
    }
  }

private:
  delta_type remaining{1000u};
};

int main() {
  entt::scheduler<std::uint32_t> scheduler;

  scheduler.attach<my_process>("foobar");
}
将其附加到调度程序

scheduler.attach<my_process>("foobar");
这些是构建错误

C:\Users\tunca\source\repos\entt-test\build>cmake --build .
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  EnttTest.cpp
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(178,28): error C2607:  static assertion failed [C:\Use
rs\tunca\source\repos\entt-test\build\entt-test.vcxproj]
C:\Users\tunca\source\repos\entt-test\EnttTest.cpp(21): message :  see reference to function template instantiation 'a 
uto entt::scheduler<uint32_t>::attach<my_process,const char(&)[7]>(const char (&)[7])' being compiled [C:\Users\tunca\ 
source\repos\entt-test\build\entt-test.vcxproj]
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(179,69): error C2440:  'initializing': cannot convert  
from 'initializer list' to 'my_process' [C:\Users\tunca\source\repos\entt-test\build\entt-test.vcxproj]
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(177,1): message :  No constructor could take the sourc
e type, or constructor overload resolution was ambiguous [C:\Users\tunca\source\repos\entt-test\build\entt-test.vcxpro 
j]
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(179,60): error C2440:  'initializing': cannot convert  
from 'initializer list' to 'entt::scheduler<uint32_t>::process_handler::instance_type' [C:\Users\tunca\source\repos\en 
tt-test\build\entt-test.vcxproj]
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(177,1): message :  No constructor could take the sourc 
e type, or constructor overload resolution was ambiguous [C:\Users\tunca\source\repos\entt-test\build\entt-test.vcxpro 
j]
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(177,1): error C3536:  'proc': cannot be used before it 
 is initialized [C:\Users\tunca\source\repos\entt-test\build\entt-test.vcxproj]
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(180,42): error C2440:  'initializing': cannot convert  
from 'int' to 'entt::scheduler<uint32_t>::process_handler::instance_type' [C:\Users\tunca\source\repos\entt-test\build 
\entt-test.vcxproj]
C:\Users\tunca\source\repos\entt\src\entt\process/scheduler.hpp(177,1): message :  No constructor could take the sourc 
e type, or constructor overload resolution was ambiguous [C:\Users\tunca\source\repos\entt-test\build\entt-test.vcxpro 
j]

失败的静态断言是:

静态资产std::是v的基础; 它失败是因为传递给entt::scheduler std::uint32_t的增量模板参数与my_进程std::int32_t基础中使用的增量模板参数不匹配。只需将结构声明更改为匹配即可消除此错误

结构my_进程:entt::进程{/*…*/}; 其他错误似乎是因为scheduler::attach将其参数转发给T的构造函数。因此,您需要添加一个接受foobar的构造函数:

my_process const char*{/*无论您想用它做什么…*/} 然后,它汇编:


谢谢,伙计✔...这让我很吃惊!