【发布时间】:2021-03-05 01:52:16
【问题描述】:
我有一个包含一些成员的结构和一个具有私有复制构造函数的对象,我如何创建一个包含该对象的数组。 例如: 我有一个对象:
class Image
{
...
private:
Image(const Image&);
Image& operator=(const Image&);
u8* pixel;
int width;
int height
}
struct ImageInformation
{
Image image;
int resolution;
}
我想为 ImageInformation 创建一个数组:向量,但这是禁止的
【问题讨论】:
-
您是在尝试创建 C 样式数组、
std::array还是std::vector?也许提供更多代码,包括触发错误的行? -
哪些构造函数是公共的?
-
std::vectror和emplace函数应该是你想要的。