#include <iostream>
struct A {
int size = 0;
int* array = nullptr;
A(int sz) : size(sz) {
array = new int[size];
}
virtual ~A(){
if(array) delete[] array;
array = nullptr;
}
};
void TestA(const A* const & ptr) {
int* tmp = ptr->array;
tmp[0] = 2;
tmp[1] = 3;
}
int main() {
A a(2);
a.array[0] = 0;
a.array[1] = 1;
std::cout << "a.array[0] = " << a.array[0] << " a.array[1] = " << a.array[1] << std::endl;
TestA(&a);
std::cout << "a.array[0] = " << a.array[0] << " a.array[1] = " << a.array[1] << std::endl;
}
这是一个伪代码