Files
XCSDD/docs/api/containers/array/operator-assign.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling
- Improve link styling with underline decoration
- Hide leaf nodes from tree, only show directories
- Fix log file path for packaged app
2026-03-19 12:44:08 +08:00

1017 B
Raw Blame History

Array::operator=

Array& operator=(const Array& other);
Array& operator=(Array&& other) noexcept;

赋值运算符,用另一个数组的内容替换当前数组的内容。

拷贝赋值(=

  • 先销毁当前所有元素
  • 分配与 other 相同大小的内存
  • 拷贝 other 中所有元素

移动赋值(=

  • 先销毁当前所有元素
  • 接管 other 的所有资源(数据指针、容量)
  • other 置为空状态

参数:

  • other - 源数组

返回: 引用自身(*this

异常:

  • 拷贝赋值:other 元素拷贝可能抛出异常

线程安全: 赋值期间不可并发访问

示例:

Containers::Array<int> arr1 = {1, 2, 3};
Containers::Array<int> arr2;

arr2 = arr1;      // 拷贝赋值arr2 现在是 {1, 2, 3}

Containers::Array<int> arr3 = {4, 5};
arr2 = std::move(arr3); // 移动赋值arr2 现在是 {4, 5}arr3 为空

相关文档