如何使用自定义值初始化模板类中的数组
How to initialize an array in a template class with a custom value?
例如
template<size_t N>
class A
{
array<int, N> m;
static A const UNIT {1, 1, ...}; // repeated N times,
// but I can't because of currently unspecified N
}
如何使用自定义值1
初始化模板大小的数组?
您可以使用填充函数。这也适用于静态常量成员。
template<size_t N>
class A {
array<int, N> m;
public:
static A const unit;
A() { m.fill(1); }
};
template<size_t N>
A<N> const A<N>::unit{};
相关文章:
- 如何在动态数组上使用搜索函数
- C++ 无法在字符数组中使用 for 循环打印字母模式
- 在 C++ 中的数组上使用阶乘函数
- 如果我在字符数组上使用 close() 会发生什么?
- "p"数组如何使用 std::normal_distribution 存储以下代码中的值C++?
- 如何在使用 make_unique<T[]>() 制作的模板类型数组上使用 std::fill?
- 如何将 std::find() 与 2d std: 数组一起使用?
- 创建整数的 2D 数组,该数组将使用两个函数用随机数填充矩阵.我做错了什么?
- 如何从文件中读取数字并在数组中使用它们?
- 是否可以在数组上使用const_cast来更改元素?
- 在缓冲区/数组中使用颜色结构
- 将 unique_ptr<std::vector> 与 c 样式数组结合使用
- 在结构数组上使用 c++ std::copy
- 数组中使用 int 中的位的不同元素数
- 如何修复将传输到 java 的 2d 数组代码使用 JNI
- 正在使用C 三元运算符中的字符串常数,一种无效的非效率数组的使用
- 在数组中使用C++中的哈希表复制数组中的元素
- 将 find_if() 与数组一起使用的代码段中出错
- C 将1D动态数组施放到2D数组以使用常规索引(例如ARR [i] [J])
- 如何在数组中使用结构化绑定作为ARG传递给某些函数