此代码编译良好:
const double d[20] {};
dlib::matrix< double, 20, 1 > m( d );
在此中断期间:
const std::array<double, 20> dd {};
dlib::matrix< double, 20, 1 > mm( dd.data() );
显示以下消息:
model.cpp: In lambda function:
model.cpp:125:101: error: no matching function for call to ‘dlib::matrix<double, 20, 1>::matrix(std::array<double, 20>::const_pointer)’
const std::array<double, 20> dd {}; dlib::matrix< double, 20, 1 > mm( dd.data() ); (void)mm;
^
compilation terminated due to -Wfatal-errors.
如果我是
reinterpret_cast< const double [20] >( dd.data() );
我被告知不允许这样做:
model.cpp: In lambda function:
model.cpp:126:100: error: invalid cast from type ‘std::array<double, 20>::const_pointer’ {aka ‘const double*’} to type ‘double [20]’
dlib::matrix< double, 20, 1 > mm( reinterpret_cast<const double [20]>(dd.data()) );
^
compilation terminated due to -Wfatal-errors.
This是我要定位的构造函数:
template <typename U, size_t len>
explicit matrix (
U (&array)[len]
);