c++ - 来自二维数组的特征图

标签 c++ c++11 c++14 eigen3

为什么会这样

typedef Matrix<double, N, N, RowMajor> Mat;
cout << Map<Mat>(&m[0][0]) << endl;

但这不是

cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;

是否可以在一行中完成所有事情?

错误是:

eigen_playground.cpp:16:46: warning: use of right-shift operator ('>>') in template argument will require parentheses in
      C++11 [-Wc++11-compat]
    cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;
                                             ^
                                     (                   )
eigen_playground.cpp:16:46: error: invalid operands to binary expression ('int' and 'double *')
    cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;
                                     ~~~~~~~~^ ~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:740:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:789:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:797:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:804:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:832:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:840:1: note: 
      candidate template ignored: could not match 'basic_istream<char, type-parameter-0-0>' against 'Eigen::StorageOptions'
operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1506:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is,
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1638:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/complex:1369:1: note: 
      candidate template ignored: could not match 'basic_istream<type-parameter-0-1, type-parameter-0-2>' against
      'Eigen::StorageOptions'
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
^
eigen_playground.cpp:16:66: error: expected a type
    cout << Map<Matrix<double, N, N, RowMajor>>(&m[0][0]) << endl;
                                                                 ^
1 warning and 2 errors generated.

最佳答案

出现错误的原因是因为在 C++11 之前,两个相邻字符“>>>”被积极解释为 right shift operator .

由于您使用的是早于 C++11 的 C++ 标准,因此只需在这两个字符之间添加一个空格即可。

cout << Map< Matrix<double, N, N, RowMajor> >(&m[0][0]) << endl;
//                             right here. ^

关于c++ - 来自二维数组的特征图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50780119/

相关文章:

c++ - OpenGL - 使用 glDrawElements 进行索引绘制

c++ - 使用 C++ std::list 迭代器替换列表中的项目

c++ - 如何正确重载属于用户定义命名空间的模板类的插入运算符?

c++ - 如何获得指向类的复制构造函数的成员函数指针?

c++ - 需要算法帮助才能找到 DAG 中的最大路径

c++ - 对 vector 使用 std::move

C++ 通过 nullptrs 标记要在 STD 列表中删除的对象

c++ - 将文件从 Boost filtering_streambuf 解压到 std::vector<unsigned char>?

c++ - 函数参数列表中的 auto 暗示模板参数

C++17 if 初始化 while 循环?