创建没有默认构造函数的结构数组
create array of structure that has no default constructor
可能重复:
没有默认构造函数的c++对象数组初始化
我有结构:
struct aa
{
int a;
char b [255];
aa(int number)
{
cout<<"creating structure "<<number<<"n";
}
~aa()
{
cout<<"destroying structure";
}
};
我正在尝试创建这种结构的数组,但这不起作用:
aa *ss = new aa[3](1);
这给了我一个编译器错误。
我该怎么做?
aa(int number=1)
・・・
aa *ss = new aa[3];
或
template <int N>
struct aa
・・・
aa(int number = N)
・・・
aa<1> *ss = new aa<1>[3];
或
#include <new>
・・・
aa(int number=0)
・・・
int main(){
aa ss[3];//local value
for(int i=0;i<3;++i)
new (ss + i) aa(1);//replacement
相关文章:
- C++将文本文件中的数据读取到结构数组中
- JSON转换为nlohmann JSON-lib中的结构数组
- 需要帮助将结构数组传递给函数
- 在 64 位边界上对齐C++结构数组?
- 带有枚举方向/类型的气泡排序结构数组
- 在C++中访问结构数组中的数据
- 从指向结构数组的指针中提取元素
- 如何制作一个地图,其中的值是C++中的结构数组
- 如何在函数中显示结构数组
- 包含作为成员C++函数的结构数组
- 如何修复函数中的 fstream 文件输入以将正确的信息存储在结构数组中?
- std::transform 将一个结构数组复制到另一个结构数组
- 将非托管结构数组封送到托管数组
- 显示结构数组
- 结构数组中所有类似字段的总和
- 结构数组的构造函数错误,错误消息:没有构造函数实例与参数列表匹配
- 在 glsl opengl 中将嵌套结构数组作为统一传递
- 使用初始化列表填充C++中的多维结构数组时出现问题
- 如何将字符串字符与结构数组进行比较?
- C++结构数组