【发布时间】:2021-03-19 12:07:39
【问题描述】:
我收到此错误:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\xmemory0:881: 错误:C2661: 'std::array
::array': 没有重载函数需要 3 个参数
在这行代码处:
template<class _Objty,
class... _Types>
static void construct(_Alloc&, _Objty * const _Ptr, _Types&&... _Args)
{ // construct _Objty(_Types...) at _Ptr
::new (const_cast<void *>(static_cast<const volatile void *>(_Ptr)))
_Objty(_STD forward<_Types>(_Args)...); // ** Error is here
}
我正在像这样使用std::array<uint, 3>:
void MyClass::myMethod(
// ...
, std::vector<std::array<uint, 3>> &indices
// ...
, const size_t ssteps
// ...
)
{
// ...
indices.reserve(2*ssteps);
auto steps = int(ssteps);
auto offs = steps;
auto last = steps - 1;
// ...
indices.emplace_back(0, last, offs);
indices.emplace_back(last, offs + last, offs);
// ...
}
我不明白为什么在 xmemory0 包含的文件中会发生此错误。任何提示表示赞赏。
【问题讨论】:
-
std::array没有像这样接受 3 个参数的构造函数,你打算做什么? -
indices.emplace_back(0, last, offs)调用构造函数array<uint, 3>::array(0, last, offs)但arraydoesn't have such constructor;使用indices.push_back({0, last, offs})代替它。