Eigen::LLT<Eigen::MatrixXd> 类型不完整

Eigen::LLT< Eigen::MatrixXd > has incomplete type

查看 this code。编译于 Ubuntu ...

MatrixXd A(3,3);
A << 4,-1,2, -1,6,0, 2,0,5;
cout << "The matrix A is" << endl << A << endl;
LLT<MatrixXd> lltOfA(A); // compute the Cholesky decomposition of A

这是一个 doctest 案例:

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <Eigen/Core>

TEST_CASE("llt")
{
  Eigen::MatrixXd A(3,3);
  A<<1,2,3,4,5,6,7,8,9;
  Eigen::LLT<Eigen::MatrixXd> lltof(A);
}

编译失败:

/src/test/test-proto.cc:40:38: error: variable ‘Eigen::LLT<Eigen::Matrix<double, -1, -1>, 1> lltof’ has initializer but incomplete type
   Eigen::LLT<Eigen::MatrixXd> lltof(A);

什么给了?这是从我的代码中减少的,以准确表示文档。

糟糕。测试用例应该是:

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include "proto.h"
#include <Eigen/Dense> //NOT Eigen/Core

TEST_CASE("llt")
{
  Eigen::MatrixXd A(3,3);
  A<<1,2,3,4,5,6,7,8,9;
  Eigen::LLT<Eigen::MatrixXd> lltof(A);
}

注意 #include 中的变化。

愚蠢的错误,但我要留给未来的自己/google。

参考这个例子link

struct Y {};
template<const Y& b> struct Z {};
Y y;
Z<y> z;  // ok: no conversion

您最好了解模板 none 类型的参数。