std::unique_ptr::operator[]
T& operator const; | | (since C++11) |
|---|
operator[]提供对由unique_ptr...
参数i应小于数组中元素的数量;否则,行为未定义。
参数
i | - | the index of the element to be returned |
|---|
返回值
返回索引处的元素i,即.get()[i]...
例
二次
#include <iostream>
#include <memory>
int main()
{
const int size = 10;
std::unique_ptr<int[]> fact(new int[size]);
for (int i = 0; i < size; ++i) {
fact[i] = (i == 0) ? 1 : i * fact[i-1];
}
for (int i = 0; i < size; ++i) {
std::cout << i << ": " << fact[i] << '\n';
}
}二次
产出:
二次
0: 1
1: 1
2: 2
3: 6
4: 24
5: 120
6: 720
7: 5040
8: 40320
9: 362880二次
另见
get | returns a pointer to the managed object (public member function) |
|---|
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

