vector<int> readFile(const string& InputPath)
ifstream inFile(InputPath); // or inputPath.c_str() for old compilers
cout << "Error reading the input file " << InputPath << ".";
exit(0); // thow would be better! Or at least return an empty vector.
for(int n; inFile >> n && myvar.size() < 10; )
But if you really really want to use new, then at least return the self-managing pointer, std::unique_ptr<int>. Never let a raw pointer escape a function, not in C++.
I see. The examples are not exception safe. So yes, they're incorrect in that respect. But they are illustrating how to construct multi-dimension arrays, so you have to take what you can from the them.
Your real problem is one of design that happens to have technical problems too. Like I said, there's no way know the size of the array being passed back from you function. No one can use an array unless the size is known, for all the caller knows the size could be zero.
So, in addition of sending an array, the size of array in all dimensions must be send as well, and using delete just have exception problem, and will not cause memory leakage after deleting heap outside the function.
^Actually, you probably want to pass in a parameter to the FreeDynamicArray function so it can actually delete the correct number of rows. Right now, it's deleting ROW loops which may be different than the number you have allocated with AllocateDynamicArray.