2013-02-15 109 views
2

我有以下程序:編譯器錯誤使用C++和eigen3

#include <Eigen/Core> 
using namespace Eigen; 

template <int _n, int _m> 
void func(Matrix<double, _m, _n> A) 
{ 
    Matrix<double, 2, 3> AA; 

    AA << 1, 0, 5, 
     2, 0, 7; 

    MatrixXd KK = AA.triangularView<Lower>(); 

    // if I uncomment this, the code won't compile 
    // MatrixXd K = A.triangularView<Lower>(); 

} 

int main() 
{ 
    Matrix<double, 2, 4> AA; 

    AA << 1, 0, 5, 17, 
     2, 0, 7, -2; 

    func(AA); 

    return 0; 
} 

我編譯g++ $(pkg-config --cflags --libs eigen3) -o main main.cc

如果指定的代碼已被註釋掉,我收到以下錯誤:

main.cc: In function ‘void func(Eigen::Matrix<double, _m, _n>)’: 
main.cc:15:40: error: expected primary-expression before ‘)’ token 
main.cc: In instantiation of ‘void func(Eigen::Matrix<double, _m, _n>) [with int _n = 4; int _m = 2]’: 
main.cc:26:10: required from here 
main.cc:15:40: error: no match for ‘operator<’ in ‘A.Eigen::MatrixBase<Eigen::Matrix<double, 2, 4> >::triangularView < (Eigen::._79)1u’ 

r

我不會在這裏發現問題。看來g ++認爲我不想將一個矩陣與Lower枚舉常量進行比較,即使我只想調用成員函數。

+1

見http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template -and-類型名稱的關鍵字 – JoergB 2013-02-15 15:50:14

回答