c++ - 编译错误:. ..未在此范围内声明

标签 c++ eigen

我是 C++ 编程新手。我必须实现一个计算矩阵的伪逆的程序。正如 Eigen 教程所建议的,我编写了如下代码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <Core>
    #include <iostream>
    #include <Eigen/Dense>
    #include <Eigen/SVD>
    #include <Eigen/Eigen>
    using namespace Eigen;
    using namespace std;



    void pinv(MatrixXf& pinvmat)
     {
    ei_assert(m_isInitialized && "SVD is not initialized.");
   double  pinvtoler=1.e-6;                       // choose tolerance 
    SingularValuesType m_sigma_inv=m_sigma;
    for ( long i=0; i<m_workMatrix.cols(); ++i) {
    if ( m_sigma(i) > pinvtoler )
     m_sigma_inv(i)=1.0/m_sigma(i);
   else m_sigma_inv(i)=0;
   }
    pinvmat = (m_matV*m_sigma_inv.asDiagonal()*m_matU.transpose());


   }

    int main()
   {

    MatrixXf A(3,2);
    A<<1,2,3,4,5,6;
    pinv(A);
    cout << "pinv =" << endl << A << endl;
    return 0;
   }

如果我尝试编译它,我会收到错误:

tut_eigen/pinv.cpp: In function ‘void pinv(Eigen::MatrixXf&)’:
tut_eigen/pinv.cpp:18:14: error: ‘m_isInitialized’ was not declared in this scope
tut_eigen/pinv.cpp:18:58: error: ‘ei_assert’ was not declared in this scope
tut_eigen/pinv.cpp:20:4: error: ‘SingularValuesType’ was not declared in this scope
tut_eigen/pinv.cpp:20:23: error: expected ‘;’ before ‘m_sigma_inv’
tut_eigen/pinv.cpp:21:22: error: ‘m_workMatrix’ was not declared in this scope
tut_eigen/pinv.cpp:22:19: error: ‘m_sigma’ was not declared in this scope
tut_eigen/pinv.cpp:23:19: error: ‘m_sigma_inv’ was not declared in this scope
tut_eigen/pinv.cpp:24:22: error: ‘m_sigma_inv’ was not declared in this scope
tut_eigen/pinv.cpp:26:15: error: ‘m_matV’ was not declared in this scope
tut_eigen/pinv.cpp:26:22: error: ‘m_sigma_inv’ was not declared in this scope
tut_eigen/pinv.cpp:26:47: error: ‘m_matU’ was not declared in this scope

为什么?它们没有在 SVD 文件中声明吗?

最佳答案

我怀疑你在谈论这个"tutorial"这与其说是一个教程,不如说是一个常见问题解答,假设您已经对这个库有所了解(顺便说一句,如果您链​​接到您的信息源,这将会很有帮助)。

这说明您可以“从外部”将 pinv() 方法添加到 SVD 中。我认为它们的意思是您可以从 SVD 派生并在派生类中提供 pinv() 方法。仅在某处键入函数并不能为编译器提供必要的上下文来确定引用名称的位置。

关于c++ - 编译错误:. ..未在此范围内声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13218306/

相关文章:

c++ - Gcc:强制编译器默认使用 unsigned char

C++ 代码有效,但似乎效率很低

c++ - 检查字符串单词是否包含数字和不包含数字

c++ - 加快地面组中所有线对之间的 L1 距离

c++ - 构造函数参数中的引用调用引用的默认构造函数

c++ - 给定两个动态 R x C 矩阵,我如何交错行以生成一个 2R x C 矩阵?

optimization - 特征是否具有自转置乘法优化,如 H.transpose()*H

c++ - 使用Eigen::Transpose <const Matrix3>的正确方法?

c++ - Eigen :围绕轴 W 执行 3D 旋转并锚定在点 P

c++ - 在复制赋值(operator=)中调用虚函数是个好主意吗?