take this with a grain of salt as I am not that experienced with C++ ( started learning C++ from 2016-2017 ), I believe this is caused by the fact that in the second code, the dic[] has become a pointer and as such caused an error, scratch that, I am sure that this is caused by the fact that dic[] has become pointer and as foreach ( that for auto is what’s called foreach ) is not supposed to traverse through pointer, it caused an error. why not make the function accept an array along with the size, and traverse through the pointer using normal for