Hello everyone, there are 2 questions:
- Is it correct to clear the memory in the same way as in the code if the calc function is located in a separate dll? If not, how is it right? Or are there any other options?
Why in the arguments of the function calc it is necessary to write a reference to the pointer Test * & test, and not Test * test?
#include <iostream> using namespace std; struct Test { int a; int b; }; **// Эта функция будет в dll** void calc(Test *& test, unsigned int &sizeTest) { sizeTest = 3; test = new Test[sizeTest]; for (uint i = 0; i < sizeTest; i++) { test[i].a = i; test[i].b = i; } } int main() { Test *test = NULL; unsigned int sizeTest = 0; calc(test, sizeTest); cout << sizeTest << endl; for (uint i = 0; i < sizeTest; i++) { cout << test[i].a << endl; cout << test[i].b << endl; } // Корректно ли тут очищать память, выделенную в другой функции? delete[] test; return 0; }
*&reference&will affect the penemen in the calling function (you have this test), and without&your test will be NULL. - nick_n_a