抛出异常:访问冲突(特征矩阵类) [英] Exception thrown: access violation (eigen matrix class)

查看:147
本文介绍了抛出异常:访问冲突(特征矩阵类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在使用Eigen矩阵库(版本3.3.7),我正在尝试测试一切,看看一切都很顺利。但是,在下面的测试程序中:



我尝试过:



So, I'm using the Eigen matrix library (version 3.3.7), and I'm trying to test things out and see that everything's going fine. However, on the test program below:

What I have tried:

#include <iostream>
#include <sstream>

#include <Eigen/Dense>

using namespace std;
using namespace Eigen;

int main()
{
	cout << "Hello World!" << endl;

	MatrixXd A;
	A << 1, 2, 3,
		4, 5, 6,
		7, 8, -9;

	cout << A << endl;

	cin.get();
	return 0;
}





我收到一个错误:





I'm getting an error:

<pre>"Exception thrown at 0x________ in Matrices.exe: 0xC0000005: Access violation writing location 0x00000000."





奇怪的是,如果我初始化Matrix3d而不是MatrixXd,一切都会好起来的。谁能帮助我并弄清楚如何解决这个问题?



Oddly enough, everything goes fine if I initialise a Matrix3d instead of a MatrixXd. Could anyone help me and figure out how to fix this?

推荐答案

这对我有用:
Eigen::MatrixXd a( 3, 3 );
a << 1, 2, 3,
     4, 5, 6,
     7, 8, 9;

std::stringstream s;
s << a;

trace( "%s\n", s.str().data() );

trace是我在我的应用中使用的输出函数。问题是MatrixXd是一个动态矩阵,你必须告诉它矩阵的大小。

trace is the output function I use in my apps. The issue is MatrixXd is a dynamic matrix and you have to tell it how big the matrix is first.


这篇关于抛出异常:访问冲突(特征矩阵类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆