想为ublas的项目功能编写C ++包装器

时间:2013-08-05 16:07:11

标签: c++ matrix ublas

最小代码示例:

#include <boost/numeric/ublas/matrix_proxy.hpp>

namespace bnu = boost::numeric::ublas;

template<class M, class IA>
bnu::matrix_indirect<M, IA> project (bnu::matrix_indirect<M, IA> &data,
    int row1, int row2, int col1, int col2) {
    return bnu::project(data,
        bnu::range(row1, row2), bnu::range(col1, col2));
}

#include <boost/numeric/ublas/matrix.hpp>

int main()
{
    bnu::matrix<int> m(4,4);
    project(m,0,1,0,1);
    return 0;
}

像这样编译:

g++ -Wall project.cpp -o project

它引发了编译器错误:

> g++ -Wall project.cpp -o project
project.cpp: In function ‘int main()’:
project.cpp:16:19: error: no matching function for call to ‘project(boost::numeric::ublas::matrix<int>&, int, int, int, int)’
project.cpp:16:19: note: candidates are:
project.cpp:7:29: note: template<class M, class IA> boost::numeric::ublas::matrix_indirect<M, IA> project(boost::numeric::ublas::matrix_indirect<M, IA>&, int, int, int, int)
project.cpp:7:29: note:   template argument deduction/substitution failed:
project.cpp:16:19: note:   ‘boost::numeric::ublas::matrix<int>’ is not derived from ‘boost::numeric::ublas::matrix_indirect<M, IA>’
(more candidates to come, but these are not important here)

我想我的project版本的标题不合适(我从/usr/include/boost/numeric/ublas/matrix_proxy.hpp复制了最合适的标题)。如何使它工作?

0 个答案:

没有答案