我无法获取元素的类型。此解决方案返回对元素类型的引用。
int arr[] = { 0, 1, 2, 3, 4, 5 };
using arrElemType = decltype(*arr);
vector<arrElemType> vec(std::cbegin(arr), std::cend(arr));
最佳答案
尝试以下操作
using arrElemType = std::remove_reference<decltype( *arr )>::type;
或
typedef std::remove_reference<decltype( *arr )>::type arrElemType;
您需要包含 header <type_traits>
关于c++ - 如何判断数组元素的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22410531/