我得到"cygwin_exception::open_stackdumpfile:转储堆栈跟踪到TestProject.exe。stackdump"错误。我的项目只不过是一个c++的HalloWorld项目,它包含了一个额外的类,我可以在其中设置和获取一个变量。我得到这个错误,在这一行,我试图设置一个矩阵变量的类型为特征。下面是我的代码:
TestProject.cpp
#include <iostream>
#include "TestClass.hpp"
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
TestClass testClass;
Eigen::MatrixXd XX = testClass.getVariable();
cout << "X = " << XX;
return 0;
}
TestClass.hpp:
#ifndef TESTCLASS_HPP_
#define TESTCLASS_HPP_
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
#include <unsupported/Eigen/MatrixFunctions>
#include <Eigen/Geometry>
class TestClass {
private:
Eigen::MatrixXd X;
public:
TestClass();
void setVariable(Eigen::MatrixXd);
Eigen::MatrixXd getVariable();
virtual ~TestClass();
};
#endif /* TESTCLASS_HPP_ */
最后是TestClass.cpp:
#include "TestClass.hpp"
using namespace std;
TestClass::TestClass() {
X << 0, 1, 2;
}
TestClass::~TestClass() {
// TODO Auto-generated destructor stub
}
void TestClass::setVariable(Eigen::MatrixXd x){
X = x;
}
/* namespace std */
Eigen::MatrixXd TestClass::getVariable(){
return X;
}
我在控制台得到的输出是:
!!!Hello World!!!
0 [main] TestProject 8416 cygwin_exception::open_stackdumpfile: Dumping stack trace to TestProject.exe.stackdump
值得一提的是,当我将类变量X的类型(以及方法和头文件中的所有相关类型)更改为整数时,我不会得到此错误,代码编译并运行。
我在网上找不到有用的信息,希望你能帮助我。
谢谢
您正在使用动态大小的矩阵X,并且您尝试在不首先设置其大小的情况下对其进行逗号初始化。这会引发一个异常:
如下所示:
Eigen提供了一个逗号初始化语法,允许用户轻松设置矩阵,矢量或数组的所有系数。简单的列出系数,从左上角开始,从从左到右,从上到下。对象的大小.
:
系数必须按顺序排列,且准确匹配矩阵的大小。否则会引发一个断言。
所以先调整矩阵的大小:
TestClass::TestClass() {
X.resize (1,3);
X << 0, 1, 2;
}