You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
580 B
22 lines
580 B
#include <array>
|
|
|
|
class MyClass {
|
|
private:
|
|
std::array<int, 10> privateArray;
|
|
public:
|
|
// 假设初始化已经在构造函数或其他地方完成
|
|
// 返回的是私有数组的副本
|
|
// const std::array<int, 10> getPrivateArrayRef() const {
|
|
// return privateArray;
|
|
// }
|
|
|
|
// 返回的是私有数组的引用
|
|
std::array<int, 10>& getPrivateArrayRef() {
|
|
return privateArray; // error
|
|
}
|
|
|
|
// 返回的是私有数组的指针
|
|
int* getPrivateArrayPtr() {
|
|
return privateArray.data(); // error
|
|
}
|
|
} |