Eigen 的 .resize(rows,cols) Matrix const MatrixXd as 'this' argument discards qualifiers error 是什么意思

What is the meaning of Eigen's .resize(rows,cols) Matrix const MatrixXd as 'this' argument discards qualifiers error

当 Matrix 参数定义为常量时,我​​得到

.resize(rows,cols) Matrix const MatrixXd as 'this' argument discards qualifiers error

    void (const Eigen::MatrixXd &X){
    X.resize(cols, rows) }

returns一个错误 但这按预期工作:

    void(Eigen::MatrixXd &X){
    X.resize(cols, rows)}

我不太熟悉 c++(除了将它用于此 class),我想知道这是什么意思?

感谢您的指点。

该警告表示您调用的 resize 函数不是 const 限定的。缺少 const 限定意味着不能在 const 左值上调用该函数。 resize是修改对象的函数。 “const”的粗略意思是不允许修改。

X是对const的左值引用,所以不能通过引用调用非const限定的函数。您试图通过 const 引用调用非 const 限定函数。由于这是不允许的,编译器已将错误告知您。