英文:
Error storing data from std::Vector to Eigen::Vector
问题
以下是您提供的代码的翻译部分:
*error: no matching function for call to object of type 'Eigen::VectorXd' (aka 'Matrix<double, Dynamic, 1>')
DenseCoeffsBase.h:362:5: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:115:41: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:178:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided
DenseCoeffsBase.h:423:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided*
上述是当我尝试将数据从标准向量存储到Eigen向量时提供的错误消息。
这是我尝试的内容。我在其他文件中创建了标准向量,并通过这些命令返回它们,然后必须将它们转换为Eigen样式的向量以与其他代码集成。我尝试了查找将标准向量数据存储到Eigen的方法,我在另一个Stack Overflow帖子中找到了这种特定方法。我不明白这个错误消息是什么意思。有人能告诉我我做错了什么吗?
还有,在尝试打印数据时,我遇到了这个错误:"引用非静态成员函数必须调用它:你是不是打算不带参数调用它"。
我以为通过调整大小我使它成为了静态向量。
我会感激帮助,并会添加任何必要的信息。我对C++相对陌生,因此希望能够提供更简单的解释,因为我对所有基本原理都不是很熟悉。
simulator.h
Eigen::VectorXd currentStartMassVector_, currentEndMassVector_, specificImpulses_;
std::vector<double> StartMassVector_, endMassVector_, SpecificImpulseVector_;
simulator.cpp
currentStartMassVector_.resize(numberOfStages_);
currentEndMassVector_.resize(numberOfStages_);
specificImpulses_.resize(numberOfStages_);
StartMassVector_ = launchVehicle->getMassStartStages();
endMassVector_ = launchVehicle->getMassEndStages();
SpecificImpulseVector_ = launchVehicle->getCurrentSpecificImpulse();
currentStartMassVector_(StartMassVector_.data(), StartMassVector_.size());
currentEndMassVector_(endMassVector_.data(), endMassVector_.size());
specificImpulses_(SpecificImpulseVector_.data(), SpecificImpulseVector_.size());
std::cout << "start mass vector" << currentStartMassVector_.transpose << std::endl;
std::cout << "end mass vector" << currentEndMassVector_.transpose << std::endl;
std::cout << "Isp vector" << specificImpulses_.transpose << std::endl;
希望这些翻译对您有帮助。如果您有任何进一步的问题,请随时提出。
英文:
*error: no matching function for call to object of type 'Eigen::VectorXd' (aka 'Matrix<double, Dynamic, 1>')
DenseCoeffsBase.h:362:5: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:115:41: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:178:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided
DenseCoeffsBase.h:423:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided*
The above was the error message provided when I try to store the data from a standard vector to a Eigen Vector
Here's what I'm trying to do. I've made std vectors in other files that I'm returning through those commands and then have to convert them to eigen style vectors to integrate with some other code.I have tried looking for ways to store std vector data into eigen and I found this particular way on another stack overflow post. I dont understand what the error messsage means. Can someone tell me what I'm doing wrong?
Also in an effort to print out the data, I get this error
"Reference to non static member function must be called:did you mean to call it with no arguments"
I thought I made it a static vector by resizing.
I'd appreciate help and will add any information necessary. I'm kind of new to C++, and would appreciate a bit simpler explanations as I'm not well versed with all the fundamentals.
simulator.h
Eigen::VectorXd currentStartMassVector_, currentEndMassVector_ ,specificImpulses_ ;
std::vector<double> StartMassVector_, endMassVector_ , SpecificImpulseVector_ ;
simulator.cpp
currentStartMassVector_.resize(numberOfStages_);
currentEndMassVector_.resize(numberOfStages_);
specificImpulses_.resize(numberOfStages_);
StartMassVector_ = launchVehicle->getMassStartStages();
endMassVector_ = launchVehicle->getMassEndStages();
SpecificImpulseVector_ = launchVehicle->getCurrentSpecificImpulse();
currentStartMassVector_(StartMassVector_.data(),StartMassVector_.size()) ;
currentEndMassVector_(endMassVector_.data(),endMassVector_.size()) ;
specificImpulses_(SpecificImpulseVector_.data(),SpecificImpulseVector_.size());
std::cout << "start mass vector" << currentStartMassVector_.transpose << std::endl;
std::cout << "end mass vector" << currentEndMassVector_.transpose << std::endl;
std::cout << "Isp vector" << specificImpulses_.transpose << std::endl;
答案1
得分: 3
只能使用构造函数来初始化以前未声明的向量。
在这种情况下,Eigen向量已经在头文件中声明。
Eigen::Map()
可以用来将数据从 std::vector<double>
复制到 Eigen::VectorXd
,就像这样:
currentStartMassVector_ = Eigen::Map<Eigen::VectorXd>(StartMassVector_.data(),StartMassVector_.size()) ;
英文:
You can only use the constructor to initialize a vector that was not previously declared.
In this case, the Eigen vectors are already declared in the header file.
Eigen::Map()
can be used to copy the data from the std::vector<double>
to the Eigen::VectorXd
, like this:
currentStartMassVector_ = Eigen::Map<Eigen::VectorXd>(StartMassVector_.data(),StartMassVector_.size()) ;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论