Array names are pointers in C++.
Your GetM code is dividing the size of the pointer by the size of the first element of the array; as it is an array of int, sizeof() the first element would be sizeof(int) so the "1" is reflecting the integer truncated division of the size of a pointer by the size of an int.
To get the length of a C++ array in C++, make the array an object of a class that records the length when the object was created and makes the length available as a property of the class.
To use C++ to get the length of a MATLAB array, call the appropriate mx* routine. MATLAB arrays point to a descriptor of the array, including each of the dimensions, and including a pointer to the actual data block. This is not the way other C++ arrays are stored (unless they have been designed for compatibility with MATLAB.)