【发布时间】:2021-06-14 20:37:47
【问题描述】:
我有一种情况,我需要将存储在一个类中的指针数组复制到另一个类。 在对this 问题的第二个回答之后,我创建了这个可重现的示例,说明我在实际项目中尝试做的事情。
#include <iostream>
#include <iterator>
struct A{};
class Something
{
public:
static constexpr int nItems = 5;
A* pA[nItems];
};
class AnotherThing
{
public:
A* pACopy[Something::nItems];
void CopyPointers(const A* pA[Something::nItems])
{
std::copy(std::begin(pA), std::end(pA), std::begin(pACopy));
}
};
int main()
{
Something something;
AnotherThing anotherThing;
anotherThing.CopyPointers(something.pA);
}
错误在std::copy(std::begin(pA), std::end(pA), std::begin(pACopy)); 行,错误是
no instance of overload function "std::begin" matches the argument list。 std::end 也一样。
【问题讨论】:
-
#include <algorithm>
标签: c++