2

I have the following program:

#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;
}

I compile it with g++ $(pkg-config --cflags --libs eigen3) -o main main.cc

If the indicated code is commented out, I get the following errors:

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

I don't unserstand the problem here. It seems like g++ thinks that I wan't to compare a matrix to the Lower enum constant, even though I just want to call a member function.

hfhc2
  • 4,182
  • 2
  • 27
  • 56
  • 1
    See http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords – JoergB Feb 15 '13 at 15:50

1 Answers1

5

You need to say MatrixXd K = A.template triangularView<Lower>();

See http://womble.decadent.org.uk/c++/template-faq.html#disambiguation

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521