You can't use range-for-loop with dynamically allocated arrays, since compiler can't deduce begin and end of this array. You should always use containers instead of it, for example std::vector.
std::vector v(size);
for(const auto& elem: v)
// do something