【问题标题】:In C++'s Eigen library, how do I solve: invalid use of incomplete type ‘const class Eigen::MatrixSquareRootReturnValue<Eigen::Matrix<float, -1, -1> >’在 C++ 的 Eigen 库中,我该如何解决:无效使用不完整类型 'const class Eigen::MatrixSquareRootReturnValue<Eigen::Matrix<float, -1, -1>>'
【发布时间】:2018-07-10 01:17:37
【问题描述】:

我在 C++ 中使用 Eigen 库来获取浮点方阵的平方根:

  MatrixXf gPrime(QUAD_EKF_NUM_STATES, QUAD_EKF_NUM_STATES);
  gPrime.setIdentity();

  auto sqrtG = gPrime.sqrt();

当我编译它时,我得到了以下错误:

.../src/QuadEstimatorEKF.cpp:255:31: error: invalid use of incomplete type ‘const class Eigen::MatrixSquareRootReturnValue<Eigen::Matrix<float, -1, -1> >’
   auto sqrtG = gPrime.sqrt()
                               ^
In file included from /.../lib/Eigen/Core:346,
                 from /.../lib/Eigen/Dense:1,
                 from /.../src/QuadEstimatorEKF.h:11,
                 from /.../src/QuadEstimatorEKF.cpp:2:
/.../lib/Eigen/src/Core/util/ForwardDeclarations.h:286:34: note: declaration of ‘class Eigen::MatrixSquareRootReturnValue<Eigen::Matrix<float, -1, -1> >’
 template<typename Derived> class MatrixSquareRootReturnValue;
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~

“不完整类型”是什么意思,我应该怎么做才能解决它?

我正在使用 C++ 11 和 g++ 8.1.1。

【问题讨论】:

  • 如果您想要矩阵平方根,请遵循 Darklighter 的回答,如果您想要系数平方根,则执行 gPrime.cwiseSqrt()gPrime.array().sqrt()sqrt(gPrime.array())。 (它们都是一样的,只是口味问题)。

标签: c++ matrix eigen


【解决方案1】:

搜索 documentation of that function 显示它是 Eigen-unsupported 的一部分并且(在顶部)

要使用此模块,请添加
#include &lt;unsupported/Eigen/MatrixFunctions&gt;
在源文件的开头。

不完整类型的无效使用

意味着编译器只找到一个声明,但在使用时需要一个定义。

【讨论】:

    【解决方案2】:

    看起来它在寻找比 P_old.sqrt() 更多的东西,你需要看看这个对象是什么样子的,它可能有你可能需要使用的 getter/setter 或原子类型。

    阅读 forward declarations 以了解您收到此错误的原因,修复它应该很简单。

    【讨论】:

    • 抱歉错误信息是重构前的,已经更正了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    相关资源
    最近更新 更多